Home php How to decrypt AES-256 CBC?

How to decrypt AES-256 CBC?




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");
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);

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.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions