如何在android中openssl_decrypt?

时间:2015-07-23 07:39:50

标签: java android encryption

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

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

1 个答案:

答案 0 :(得分:0)

您可以尝试以下方法:

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;
        }
}