I’m trying to encrypt a String using TripleDESEncryption and followed this example I found on the internet (link: http://www.blackberry.com/developers/docs/3.6api/net/rim/device/api/crypto/doc-files/CryptoTest.html#sampleMD5Digest):
// sampleTripleDESEncryption
private static int sampleTripleDESEncryption( byte[] secretKey, byte[] plainText, byte[] cipherText ) throws CryptoTokenException, CryptoUnsupportedOperationException
{
// Create a new Triple-DES key based on the 24 bytes in the secretKey array
TripleDESKey key = new TripleDESKey( secretKey );
// Create a new instance of the Triple-DES encryptor engine, passing in the newly
// created key
TripleDESEncryptorEngine engine = new TripleDESEncryptorEngine( key );
// Encrypt one block (8 bytes) of plainText into cipherText
engine.encrypt( plainText, 0, cipherText, 0 );
// Return the block size of the engine
return engine.getBlockLength();
}
However, I want to convert the encrypted data to String. I’m not sure if the cipherText variable is the one to be converted. Any help? How am I going to convert it?
You just don’t expect that result will be returned through parameter.
So first of all allocate enough buffer in
chiperText. Call the method and you will have result inchiperTextbuffer with returned length (return value).