There is a given code (Java), which encrypts a specific text:
Public String Encrypt (String Plaintext, String Password) Thrown Exception
{
Messagedigest Digest = Messagedigest.getInstance ("SHA-256");
Digest.update (password.getbytes ("UTF-8"));
byte [] KeyBytes = New Byte [32];
System.ArrayCopy (Digest.digest (), 0, KeyBytes, 0, KeyBytes.Length);
Cipher = Cipher.getInstance ("AES / CBC / ZerobyTepadding");
Key = New SecretKeyspec (Keybytes, "AES);
spec = getiv ();
cipher.init (Cipher.encrypt_mode, Key, Spec);
Byte [] Encrypted = Cipher.dofinal (PlainText.getBytes (UTF-8));
String EncryptedText = New String (Base64.Encode (Encrypted, Base64.Default), "UTF-8");
RETURN ENCRYPTEDTEXT;
}
Public AlgorithMparameterspec Getiv () // Get IV
{
byte [] iv = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,};
Ivparameterspec ivparameterspec;
IVParameterspec = New IVParameterspec (IV);
RETURN IVPARAMETERSPEC;
}
How can I decrypt the resulting text on the server using PHP?
Answer 1, Authority 100%
To decrypt the text, you need to conduct inverse operations: decoded from BASE64, get an array of bytes, decode an array using password and initialization vector (Example of the lyuba https://github.com/lt/php-aes ), and convert a decoded array into a string.