BlackBerry TripleDESEncryption输出转换为String

时间:2012-08-31 07:14:52

标签: blackberry encryption

我正在尝试使用TripleDESEncryption加密字符串,并按照我在互联网上找到的这个示例(链接: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();
} 

但是,我想将加密数据转换为String。我不确定cipherText变量是否是要转换的变量。有帮助吗?我怎么转换它?

1 个答案:

答案 0 :(得分:2)

您不希望通过参数返回结果。

首先,在chiperText中分配足够的缓冲区。调用该方法,您将得到具有返回长度(返回值)的chiperText缓冲区。