EpicUsaMan2016-12-04 00:31:49
EpicUsaMan, 2016-12-04 00:31:49

Aes-256-crt crypto not working?

There is code in PHP and JS to encrypt and decrypt using AES-256-CTR, PHP does a great job with both decryption and encryption, but JS returns an empty string. Why?

function encrypt ($text) {
return openssl_encrypt($text, "aes-256-ctr", "PASSWORD");

function decrypt ($crypt) {
return openssl_decrypt($crypt, "aes-256-ctr", "PASSWORD");

function decrypt(text) {
  let decipher = crypto.createDecipher("aes-256-ctr", "PASSWORD");
  let dec = decipher.update(text, "hex", "utf8");
  dec += decipher.final("utf8");
  return dec;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
timfcsm, 2016-12-04

in update input encoding (second argument) utf8, ascii, or latin1 ; output (third argument) latin1, base64 or hex
final output also latin1, base64 or hex

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question