0

I have the following javascript code CryptoJS to encrypt the variable n:

var l;
var n="190.207.78.120";
return l=D.enc.Base64.parse(btoa("AD7552C821266C8255348F726CAB9589")),D.AES.encrypt(n,l,{mode:D.mode.ECB,padding:D.pad.Pkcs7}).toString();

Output:

IV9Ada02dMtXNr8zDfZDUA==

The variable l is my password but when I try to display it with console.log(l) it is an object:

sigBytes:32, words: [1094989621, 892486456, 842084918, 910374962, 892678964, 944125746, 910377282, 959789113]

In the same way I can decrypt with the following code:

var l;
var n="IV9Ada02dMtXNr8zDfZDUA==";
return l=D.enc.Base64.parse(btoa("AD7552C821266C8255348F726CAB9589")),D.AES.decrypt(n,l,{mode:D.mode.ECB,padding:D.pad.Pkcs7}).toString(D.enc.Utf8);

Output:

190.207.78.120

How can I extract the password with which the variable n is encrypted or decrypted?

Amulya K Murthy
  • 130
  • 1
  • 2
  • 15
Oni
  • 41
  • 8
  • Off topic, but ECB mode is almost definitely the wrong choice. In fact, you really need to be using AEAD modes (GCM is popular for use with AES) for every use case ever. Ciphertext malleability is a real-world problem. – Reid Rankin Oct 15 '19 at 05:53

1 Answers1

0

You can't. You didn't encrypt the password, but the variable n, the password is used to encrypt/decrypt, but is not encrypted itself.

UPDATE: If by "decrypting the password" you mean to simply display the integer array you got there as a string, that's a different issue and very much depends on what you want the result to look like (for example a HEX string or a ASCII string).

(Possible duplicate of Word Array to String)

Markus Dresch
  • 5,290
  • 3
  • 20
  • 40
  • What would the equivalent of Pycryptodome be like? That is, the CryptoJS code that I left above if it was Pycryptodome – Oni Oct 15 '19 at 16:59