iphone crypt AES256如何输出32 Byte Hex String?

时间:2011-05-13 18:51:44

标签: iphone encryption aes bouncycastle

亲爱的大师, 我在带有bouncy castle lib的java上有代码,如下所示:

private static String AES (boolean encrypt, String inputString, String keyString) {
        byte [] input, cipherText;
        int outputLen;

            BufferedBlockCipher cipher = new BufferedBlockCipher(new AESEngine());
        input = HexString.hexToBytes(inputString);

        cipher.init (encrypt, new KeyParameter (HexString.hexToBytes(keyString)));
        cipherText = new byte[cipher.getOutputSize(input.length)];
        outputLen = cipher.processBytes( input, 0, input.length, cipherText, 0);

        try {
            cipher.doFinal (cipherText, outputLen);
        } catch (DataLengthException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InvalidCipherTextException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return HexString.bytesToHex(cipherText);
    }

这个输出方法如下:

screet:6a7573742074657374696e6700000000

键:6f2ca4106748c1eaeff88bdad4049285

结果:f1ecd6bc3109b1f2355be3a32dd49874

这是我在IOS上的代码:

NSLog( @"Screet     : %@", secret );
NSLog( @"Key        : %@", key );
NSString *encryptedString = [secret AES256EncryptWithKey:key];
NSLog( @"Result     : %@", encryptedString );
NSLog( @"Result Hex : %@", [NSString stringToHex:encryptedString] );

Screet:6a7573742074657374696e6700000000

重点:6f2ca4106748c1eaeff88bdad4049285

结果:UBXp6lFnM + XAZvVeOuYkI / T4 + brXyGBmzGOUMO + XrGS8MWGDVb0RrZGBHyw2l2Ml

结果十六进制:55425870366c466e4d2b58415a7656654f75596b492f54342b6272587947426d7a474f554d4f2b58724753384d57474456623052725a4742487977326c324d6c

我在这个论坛中使用NSData + AESCrpt。 是否有任何建议,为了结果是相同的ios和java(32字节串)? 感谢大师的帮助:)。

0 个答案:

没有答案