首页 > 解决方案 > Android Java:试图让这个 AES 加密库工作,但它没有

问题描述

我正在尝试测试这个库

http://blog.cwill-dev.com/2012/10/09/encryption-between-javaandroid-and-php/

使用此代码

 ApiCrypter ApiCrypter = new ApiCrypter();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my_profile);

    try {
        String encryptedRequest = ApiCrypter.bytesToHex(this.ApiCrypter.encrypt("hello world"));
        Toast.makeText(this, encryptedRequest, Toast.LENGTH_LONG).show();
    } catch (Exception e) {
        e.printStackTrace();
    }

在页面中提到的示例中

String encryptedRequest = ApiCrypter.bytesToHex(this.apiCrypter.encrypt(jsonParams.toString()));

但是“apiCrypter”不存在所以我使用了实例“ApiCrypter”

但是吐司根本没有被触发。我试图在 TextView 中显示该值,但它也是空的。请问有什么帮助吗?

标签: javaandroidencryptionaes

解决方案


尝试更换:

ApiCrypter ApiCrypter = new ApiCrypter();

和:

ApiCrypter apiCrypter = new ApiCrypter();

接着:

String encryptedRequest = ApiCrypter.bytesToHex(this.apiCrypter.encrypt(jsonParams.toString()));

推荐阅读