06-22-2011 08:17 AM - edited 06-22-2011 08:33 AM
I am desining an application in which I want to encrypt the message and i did it by using TripleDESEncryptorEngine
but the problem is that TripleDESEncryptorEngine genrate random encrypted data everytime for the same text
but I want to genrate same encypted data for the same text everytime if anyone have information regarding this please reply as soon as possible
06-22-2011 05:49 PM
"TripleDESEncryptorEngine generate random encrypted data everytime for the same text "
Since this algorithm was the preferred US standard for encryption for a number of years, and the BlackBerry implementation used to be the standard encryption for BES data traffic (at least that is what I have been told), I doubt very much that this will generate random encrypted data. I suspect you are not using correctly.
That said, I've always found it a tricky algorithm to use and I recommend that you look instead at AES. not only is it a stronger encryption, it is also more efficient!!
You should find sample code for doing encryption if you look round the API. In case you can't, here is a copy from the OS 5.0 API doc.
private static int sampleAESEncryption(
byte secretKey, int keyLength, int blockLength, byte plainText, byte cipherText, int dataLength )
throws CryptoException, IOException
// First create the AES key based on the bytes in secretKey using
// keyLength bits as the length
AESKey key = new AESKey( secretKey, keyLength );
// Create the output stream to store the encrypted data
NoCopyByteArrayOutputStream out = new NoCopyByteArrayOutputStream();
// Now create the block encryptor and pass in a new instance
// of an AES encryptor engine with the specified block length
BlockEncryptor cryptoStream = new BlockEncryptor(
new AESEncryptorEngine( key ), out );
// Write the plaintext to the AES encryption stream
cryptoStream.write( plainText, 0, dataLength );
// Copy the encrypted data from the output stream to the ciphertext
// buffer and return the number of bytes actually in the buffer
int finalLength = out.size();
System.arraycopy( out.getByteArray(), 0, cipherText, 0, finalLength );