简体   繁体   中英

Java AES256encrypt in Objective-C

need help with this code in Java. I need something equivalent in Objective-C. Any help?

thx

public static final String getAES256(final String text){
    try{
        SecretKeySpec specKey = new SecretKeySpec(Hex.decode(MERCHANT_KEY), "AES");
        Cipher aesCipher =  Cipher.getInstance("AES/ECB/ZeroBytePadding");
        aesCipher.init(Cipher.ENCRYPT_MODE, specKey);
        byte[] result = aesCipher.doFinal(Hex.decode(text));
        return convToHex(result);
    }catch(Exception e){
        e.printStackTrace();
    }
    return null;
}

Getting encryption code right is insanely difficult.

If you control both the server and client side, I would recommend that you make use of RNCryptor by @rob-napier.

You can find the code here: https://github.com/RNCryptor/RNCryptor In the read me is a link to a Java implementation: https://code.google.com/p/jncryptor/

If you can't change the server side stuff, then RNCryptor is a great example on how to do it right in Objective C

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM