简体   繁体   English

Objective-C中的Java AES256encrypt

[英]Java AES256encrypt in Objective-C

need help with this code in Java. 在Java中需要有关此代码的帮助。 I need something equivalent in Objective-C. 我需要在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. 如果同时控制服务器端和客户端,我建议您使用@ rob-napier的RNCryptor。

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/ 您可以在此处找到代码: https : //github.com/RNCryptor/RNCryptor在“自述文件”中是指向Java实现的链接: 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 如果您不能更改服务器端的内容,那么RNCryptor是一个很好的示例,说明了如何在Objective C中正确执行此操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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