Help on JBASE 3DES BASE64 Encryption

159 views
Skip to first unread message

Imran Akbar

unread,
Jun 24, 2011, 6:40:33 AM6/24/11
to jb...@googlegroups.com
Hi,

Doing  encryption with JBASE_CRYPT_3DES_BASE64 on JBASE, with same algorithm i'm trying to encrypt the same String on Java,but  it gives different outputs,

Also  tried to encrypt at jbase end and decrypt with java using 3DES_BASE64 with same key but it throws Bad Padding Exception.

Below are my code snippets:

INCLUDE JBC.h

cipher = JBASE_CRYPT_3DES_BASE64

key = "566AB0D61A568842DBBF9F27"

str = "String to encrypt"

enc = ENCRYPT( str, key, cipher )

CRT enc


Output : /CryFPPNO4xuKIMqxLpkXKmNOgtgOZYg


and here is the java Code:

public DESedeEncryption() throws Exception

{

myEncryptionKey = "566AB0D61A568842DBBF9F27";

myEncryptionScheme = DESEDE_ENCRYPTION_SCHEME;

keyAsBytes = myEncryptionKey.getBytes(UNICODE_FORMAT);

myKeySpec = new DESedeKeySpec(keyAsBytes);

mySecretKeyFactory = SecretKeyFactory.getInstance(myEncryptionScheme);

cipher = Cipher.getInstance(myEncryptionScheme);

key = mySecretKeyFactory.generateSecret(myKeySpec);

}

 

/**

* Method To Encrypt The String

*/

public String encrypt(String unencryptedString) {

String encryptedString = null;

try {

cipher.init(Cipher.ENCRYPT_MODE, key);

byte[] plainText = unencryptedString.getBytes(UNICODE_FORMAT);

byte[] encryptedText = cipher.doFinal(plainText);

BASE64Encoder base64encoder = new BASE64Encoder();

encryptedString = base64encoder.encode(encryptedText);

} catch (Exception e) {

e.printStackTrace();

}

return encryptedString;

}


Output : /CryFPPNO4ygWJJwXv5P3SnBi7rMnrAh

on checking the output the first 10 characters are same, and differs from there.

leave your comments


Reply all
Reply to author
Forward
0 new messages