开发者

How iphone crypt AES256 output 32 Byte Hex String?

Dear Gurus, I have code on java with bouncy castle lib, like this :

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 blo开发者_如何学Pythonck
            e.printStackTrace();
        }
        return HexString.bytesToHex(cipherText);
    }

this output methode like this :

screet : 6a7573742074657374696e6700000000

key : 6f2ca4106748c1eaeff88bdad4049285

Result : f1ecd6bc3109b1f2355be3a32dd49874

and this is my code on IOS :

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

Screet : 6a7573742074657374696e6700000000

Key : 6f2ca4106748c1eaeff88bdad4049285

Result : UBXp6lFnM+XAZvVeOuYkI/T4+brXyGBmzGOUMO+XrGS8MWGDVb0RrZGBHyw2l2Ml

Result Hex : 55425870366c466e4d2b58415a7656654f75596b492f54342b6272587947426d7a474f554d4f2b58724753384d57474456623052725a4742487977326c324d6c

I use NSData+AESCrpt from this forum. is there any suggestion that in order the result is same ios and java (32 Byte on String) ? Thanks for gurus help :).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜