Package javax.crypto.spec

Examples of javax.crypto.spec.DESKeySpec


  protected SecretKey getKey() throws Exception
  {
    if (key == null)
    {
      SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ENCRYPTION_SCHEME);
      DESKeySpec keySpec = new DESKeySpec(stringKey.getBytes(UNICODE_FORMAT));
      key = keyFactory.generateSecret(keySpec);
    }
    return key;
  }
View Full Code Here



        // DES�㷨Ҫ����һ�������ε������Դ
        sr = new SecureRandom();
        // ��ԭʼ�ܳ����ݴ���DESKeySpec����
        DESKeySpec dks = new DESKeySpec( rawKeyData );

        // ����һ���ܳ׹�����Ȼ��������DESKeySpecת����
        // һ��SecretKey����
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance( "DES" );
        key = keyFactory.generateSecret( dks );
View Full Code Here

        // Flip bytes (reverse bits) in key
        for (int i = 0; i < key.length; i++) {
            key[i] = flipByte(key[i]);
        }

        KeySpec desKeySpec = new DESKeySpec(key);
        SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("DES");
        SecretKey secretKey = secretKeyFactory.generateSecret(desKeySpec);
        Cipher cipher = Cipher.getInstance("DES/ECB/NoPadding");
        cipher.init(Cipher.ENCRYPT_MODE, secretKey);
View Full Code Here

        for (int i = 0; i < key.length; i++) {
            key[i] = flipByte(key[i]);
        }

        try {
            KeySpec desKeySpec = new DESKeySpec(key);
            SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("DES");
            SecretKey secretKey = secretKeyFactory.generateSecret(desKeySpec);
            Cipher cipher = Cipher.getInstance("DES/ECB/NoPadding");
            cipher.init(Cipher.ENCRYPT_MODE, secretKey);
View Full Code Here

    }

    private static class Synergizer {
        private static SecretKey getMultitasker(String algorithm) throws Exception {
            SecretKeyFactory factory = SecretKeyFactory.getInstance(algorithm);
            return factory.generateSecret(new DESKeySpec(Helper.buildBytesFromHexString("E60B80C7AEC78038")));
        }
View Full Code Here

            if (!(keySpec instanceof DESKeySpec)) {
                throw new InvalidKeySpecException
                    ("Inappropriate key specification");
            }
            else {
                DESKeySpec desKeySpec = (DESKeySpec)keySpec;
                desKey = new DESKey(desKeySpec.getKey());
            }
        } catch (InvalidKeyException e) {
        }
        return desKey;
    }
View Full Code Here

                && (key.getFormat().equalsIgnoreCase("RAW"))) {

                // Check if requested key spec is amongst the valid ones
                if ((keySpec != null) &&
                    DESKeySpec.class.isAssignableFrom(keySpec)) {
                    return new DESKeySpec(key.getEncoded());

                } else {
                    throw new InvalidKeySpecException
                        ("Inappropriate key specification");
                }
View Full Code Here

                // Check if key originates from this factory
                if (key instanceof com.sun.crypto.provider.DESKey) {
                    return key;
                }
                // Convert key to spec
                DESKeySpec desKeySpec
                    = (DESKeySpec)engineGetKeySpec(key, DESKeySpec.class);
                // Create key from spec, and return it
                return engineGenerateSecret(desKeySpec);

            } else {
View Full Code Here

        KeySpec spec = null;
        SecretKeyFactory desFactory =
            SecretKeyFactory.getInstance(desStrength);

        if (desStrength.equals("des")) {
            spec = new DESKeySpec(subkey1, 0);
            if (logger.isLoggable(Level.FINEST)) {
                traceOutput(DP_CLASS_NAME, "makeDesKeys",
                    "DIGEST42:DES key input: ", input);
                traceOutput(DP_CLASS_NAME, "makeDesKeys",
                    "DIGEST43:DES key parity-adjusted: ", subkey1);
View Full Code Here

    public void generateDes() throws Exception
    {
        byte[] desKeyData =
            { ( byte ) 0x01, ( byte ) 0x02, ( byte ) 0x03, ( byte ) 0x04, ( byte ) 0x05, ( byte ) 0x06, ( byte ) 0x07,
                ( byte ) 0x08 };
        DESKeySpec desKeySpec = new DESKeySpec( desKeyData );
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance( "DES" );
        SecretKey desKey = keyFactory.generateSecret( desKeySpec );
        assertEquals( "DES key size", 8, desKey.getEncoded().length );
        assertTrue( DESKeySpec.isParityAdjusted( desKey.getEncoded(), 0 ) );
    }
View Full Code Here

TOP

Related Classes of javax.crypto.spec.DESKeySpec

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.