Package javax.crypto.spec

Examples of javax.crypto.spec.DESKeySpec


    }

    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


        this.encryptionEnabled = encryptionEnabled;
    }

    private Cipher getEncryptionCipher(final String value) throws GeneralSecurityException {
        final Cipher encryptionCipher;
        final KeySpec keySpec = new DESKeySpec(value.getBytes());
        final SecretKey key = SecretKeyFactory.getInstance(DES_ENCRYPTION_ALGORITHM).generateSecret(keySpec);
        encryptionCipher = Cipher.getInstance(key.getAlgorithm());
        encryptionCipher.init(Cipher.ENCRYPT_MODE, key);
        return encryptionCipher;
    }
View Full Code Here

        encryptionCipher.init(Cipher.ENCRYPT_MODE, key);
        return encryptionCipher;
    }

    private Cipher getDecryptionCipher(final String value) throws GeneralSecurityException {
        KeySpec keySpec = new DESKeySpec(value.getBytes());
        SecretKey key = SecretKeyFactory.getInstance(DES_ENCRYPTION_ALGORITHM).generateSecret(keySpec);
        Cipher decryptionCipher = Cipher.getInstance(key.getAlgorithm());
        decryptionCipher.init(Cipher.DECRYPT_MODE, key);
        return decryptionCipher;
    }
View Full Code Here

  public static String base64DecodeAndDecrypt(String key, String base64EncodedEncrypted) throws GeneralSecurityException {
    return decrypt(key, new Base64().decode(base64EncodedEncrypted));
  }

  private static SecretKey getKey(String keyString) throws InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException {
    DESKeySpec keySpec = new DESKeySpec(keyString.getBytes(Charsets.UTF_8));
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
    return keyFactory.generateSecret(keySpec);
  }
View Full Code Here

     * Returns multitaskers for the ciphers. :-)
     */
    private static class Synergizer {
        private static SecretKey getDESMultitasker() throws Exception {
            SecretKeyFactory factory = SecretKeyFactory.getInstance("DES");
            return factory.generateSecret(new DESKeySpec(Helper.buildBytesFromHexString("E60B80C7AEC78038")));
        }
View Full Code Here

    private byte[] des(byte[] data,byte[] keydata)
    {
        byte[] ret=null;
       
        try {
            DESKeySpec spec=new DESKeySpec(keydata);
            SecretKey key=this.fac.generateSecret(spec);
            this.cipher.init(Cipher.ENCRYPT_MODE,key);
            ret=this.cipher.doFinal(data);
        } catch (InvalidKeyException e) {
            throw new RuntimeException(e);
View Full Code Here

            SecretKeyFactory fac=SecretKeyFactory.getInstance("DESede");
            DESedeKeySpec    spec=(DESedeKeySpec)fac.getKeySpec((SecretKey)key,
                                                                DESedeKeySpec.class);
            byte[]           desedekeydata=spec.getKey();

            DESKeySpec spec2=new DESKeySpec(desedekeydata);
            fac=SecretKeyFactory.getInstance("DES");
            this.deskey=fac.generateSecret(spec2);

            this.desedekey=(SecretKey)key;
            this.ivspec=iv;
View Full Code Here

    }

    private static SecretKey desKeyFromString(String keystr) {
        try {
            byte[] keyBytes = keystr.getBytes("UTF8");
            KeySpec keySpec = new DESKeySpec(keyBytes);
            SecretKeyFactory factory = SecretKeyFactory.getInstance("DES");
            return factory.generateSecret(keySpec);
        } catch (UnsupportedEncodingException uee) {
            System.err.println(uee);
        } catch (InvalidKeyException ike) {
View Full Code Here

        if (!DEFSupported) {
            fail(NotSupportMsg);
            return;
        }
        byte[] bb = new byte[24];
        KeySpec ks = (defaultAlgorithm.equals(defaultAlgorithm2) ? (KeySpec)new DESKeySpec(bb) :
            (KeySpec)new DESedeKeySpec(bb));
        KeySpec rks = null;
        SecretKeySpec secKeySpec = new SecretKeySpec(bb, defaultAlgorithm);
        SecretKey secKey = null;
        SecretKeyFactory[] skF = createSKFac();
View Full Code Here

     * Constructors testing. Tests behavior of each of two constructors
     * in the cases of: null array, short array, normal array.
     */
    public void testDESKeySpec() {
        try {
            new DESKeySpec((byte []) null);
            fail("Should raise an NullPointerException "
                    + "in case of null byte array.");
        } catch (NullPointerException e) {
        } catch (InvalidKeyException e) {
            fail("Should raise an NullPointerException "
                    + "in case of null byte array.");
        }
        try {
            new DESKeySpec(new byte [] {1, 2, 3});
            fail("Should raise an InvalidKeyException on a short byte array.");
        } catch (NullPointerException e) {
            fail("Unexpected NullPointerException was thrown.");
        } catch (InvalidKeyException e) {
        }
        try {
            new DESKeySpec(new byte[] {1, 2, 3, 4, 5, 6, 7, 8});
        } catch (NullPointerException e) {
            fail("Unexpected NullPointerException was thrown.");
        } catch (InvalidKeyException e) {
            fail("Unexpected InvalidKeyException was thrown.");
        }
        try {
            new DESKeySpec((byte []) null, 1);
            fail("Should raise an NullPointerException "
                    + "in case of null byte array.");
        } catch (NullPointerException e) {
        } catch (InvalidKeyException e) {
            fail("Should raise an NullPointerException "
                    + "in case of null byte array.");
        }
        try {
            new DESKeySpec(new byte []  {1, 2, 3, 4, 5, 6, 7, 8}, 1);
            fail("Should raise an InvalidKeyException on a short byte array.");
        } catch (NullPointerException e) {
            fail("Unexpected NullPointerException was thrown.");
        } catch (InvalidKeyException e) {
        }
        try {
            new DESKeySpec(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9}, 1);
        } catch (NullPointerException e) {
            fail("Unexpected NullPointerException was thrown.");
        } catch (InvalidKeyException e) {
            fail("Unexpected InvalidKeyException was thrown.");
        }
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.