当前位置: 代码迷 >> java >> 如何在Android中打开openssl_decrypt?
  详细解决方案

如何在Android中打开openssl_decrypt?

热度:71   发布时间:2023-08-02 11:04:04.0

我有代码$value = openssl_encrypt($value, "AES-258", "123456789012acsdzxcsdweasd", 0, $123456789012345); 在我的PHP中。 然后$ value使用json_encoded传递。

现在,我想使用openssl_decrypt在android中解密该$ value,但没有人为其构建库。 如何以简单的方式做到这一点?

您可以尝试以下方法:

public class DecryptUtils{
    public static String AES ( byte [] cipherText, String encryptionKey ) 
        {
            String decrypted = null;

            try
            {
                Cipher cipher = Cipher.getInstance ( "AES");
                SecretKeySpec key = new SecretKeySpec ( encryptionKey.getBytes ( "UTF-8" ), "AES" );
                cipher.init ( Cipher.DECRYPT_MODE, key);
                decrypted = new String ( cipher.doFinal ( cipherText ), "UTF-8" );a
            }
            catch ( Exception e )
            {
                e.printStackTrace()
            }

            return decrypted;
        }
}
  相关解决方案