Package javax.crypto.spec

Examples of javax.crypto.spec.DESKeySpec


      buf = new char[1024];
    }

    fReaderSource.close();

    DESKeySpec keySpec = null;
    keySpec = new DESKeySpec(bkey);

    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
    SecretKey key = keyFactory.generateSecret(keySpec);

    byte[] cleartext = fileData.toString().getBytes("UTF8");
View Full Code Here


    reader.close();

    try {

      DESKeySpec keySpec = null;
      keySpec = new DESKeySpec(generateBytes());

      SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
      SecretKey key = keyFactory.generateSecret(keySpec);

      String encrypedContentFile = fileData.toString();
View Full Code Here

        byte[] keyBytes = decode (keyInput);
        byte[] ivBytes = decode (specInput);

        try {
            ivspec = new IvParameterSpec(ivBytes);
            DESKeySpec dkey = new DESKeySpec(keyBytes);
            key = new SecretKeySpec(dkey.getKey(), "DES");
            deCipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
            enCipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
        } catch (NoSuchAlgorithmException e) {
            throw new EncryptionException (e);
        } catch (NoSuchPaddingException e) {
View Full Code Here

        byte[] toCrypt = new byte[LONG_SIZE_IN_BYTES + dataBytes.length];
        System.arraycopy(prependedBytes, 0, toCrypt, 0, LONG_SIZE_IN_BYTES);
        System.arraycopy(dataBytes, 0, toCrypt, LONG_SIZE_IN_BYTES, dataBytes.length);


        DESKeySpec desKeySpec = new DESKeySpec(CRYPTO_PASSWORD.getBytes());
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(cipher);
        SecretKey secretKey = keyFactory.generateSecret(desKeySpec);

        Cipher desCipher = Cipher.getInstance(cipher);
        desCipher.init(Cipher.ENCRYPT_MODE, secretKey);
View Full Code Here

     * @throws InvalidKeySpecException if the given key specification is inappropriate for this secret-key factory to
     *         produce a secret key.
     * @throws IOException if an I/O error occurs.
     */
    public static String decrypt(String cipher, String data) throws InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeySpecException, IOException {
        DESKeySpec desKeySpec = new DESKeySpec(CRYPTO_PASSWORD.getBytes());
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(cipher);
        SecretKey secretKey = keyFactory.generateSecret(desKeySpec);

        Cipher desCipher = Cipher.getInstance(cipher);
        desCipher.init(Cipher.DECRYPT_MODE, secretKey);
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

    public DesEncrypter(String passPhrase) {
      KeySpec keySpec = null;
        SecretKey key = null;
    try {
      keySpec = new DESKeySpec(passPhrase.getBytes());
      key = SecretKeyFactory.getInstance("DES").generateSecret(keySpec);
            ecipher = Cipher.getInstance("DES");
            dcipher = Cipher.getInstance("DES");
            ecipher.init(Cipher.ENCRYPT_MODE, key);
            dcipher.init(Cipher.DECRYPT_MODE, key);
View Full Code Here

      byte[] keyAsBytes = encryptionKey.getBytes(UNICODE_FORMAT);

      if (encryptionScheme.equals(DESEDE_ENCRYPTION_SCHEME)) {
        keySpec = new DESedeKeySpec(keyAsBytes);
      } else if (encryptionScheme.equals(DES_ENCRYPTION_SCHEME)) {
        keySpec = new DESKeySpec(keyAsBytes);
      } else {
        throw new IllegalArgumentException(
            "Encryption scheme not supported: " + encryptionScheme);
      }
View Full Code Here

      byte[] keyAsBytes = encryptionKey.getBytes(UNICODE_FORMAT);

      if (encryptionScheme.equals(DESEDE_ENCRYPTION_SCHEME)) {
        keySpec = new DESedeKeySpec(keyAsBytes);
      } else if (encryptionScheme.equals(DES_ENCRYPTION_SCHEME)) {
        keySpec = new DESKeySpec(keyAsBytes);
      } else {
        throw new IllegalArgumentException(
            "Encryption scheme not supported: " + encryptionScheme);
      }
View Full Code Here

        //System.err.println(in.length);
//        if(in.length  24){
//            in = new byte[];
//
//        }
        final DESKeySpec keySpec = new DESKeySpec(in);
        final SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
        key = keyFactory.generateSecret(keySpec);

        cipher = Cipher.getInstance("DES");//"DES/ECB/PKCS5Padding");//"DES"); // cipher is not thread safe
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.