Encrypt in java decrypting in openssl
I am using below class to encrypt the data. I want to decrypt the encrypted data by this class using openssl. I am trying to run openssl enc -aes-128-ebc -d -in a.in -out a.out, but I keep getting bad magic number.
public class ByteEncrypter {
public static final String encryptionScheme = "AES";
private SecretKeySpec skeySpec;
private Cipher cipher;
private static final String UNICODE_FORMAT = "UTF8";
public ByteEncrypter( String encryptionKey )
{
if ( encryptionKey == null )
throw new IllegalArgumentException( "encryption key was null" );
try
{
byte[] keyAsBytes = encryptionKey.getBytes( UNICODE_FORMAT );
skeySpec = new SecretKeySpec(keyAsBytes, encryptionScheme);
cipher = Cipher.getInstance( encryptionScheme );
}
catch (Exception e){
if(Debug.pvshDebugLevel > 0 ) System.out.println("Failed to create ByeEncrypter");
e.printStackTrace();
}
}
public byte [] encrypt(byte [] data) throws ArchiveServiceExceptionImpl{
if (null == data || data.length <=0){
throw new IllegalArgumentException( "encryption key was null" );
}
byte[] encrypted = null;
try{
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
encrypted = cipher.doFinal(data);
}catch(Exception e){
if(Debug.pvshDebugLevel > 0 ) System.out.println("Failed to encrypt ");
e.printStackTrace();
}
return encrypted;
}
public byte [] decrypt(byte [] data) throws ArchiveServiceExceptionImpl{
if (null == data || data.length <=0){
throw new IllegalArgumentException( "encryption key was null" );
}
byte[] decrypted = null;
try{
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
decrypted = cipher.doFinal(data);
}catch(Exception e){
if(Debug.pvshDebugLevel > 0 ) System.out.println("Failed to Decrypt");
e.printStackTrace();
}
return decrypted;
}
}