Some background information, you can skip this part for the current issue.
This is my third question about this topic here on stackoverflow. To be complete, these are other AES issues with crypt-js and PyCrypto and Map AES de / encryption in python and javascript . Unfortunately, my last attempt received two questions for the original question. The problem is that even I did not know what my real question is. I just rummaged through to find the real question I was looking for. With reviews in the comments and reading some additional information, I updated my question. I think I’ll dig up the right question. But after my updates, my problem did not get more views. Therefore, I really hope that this question is now more clear and understandable - even I know that my problem is now: D
Thanks to everyone for doing stackoverflow in this cool community - I often found solutions to my problems here. Please continue to provide feedback on bad issues so that they can be improved and updated, which increases this vast base of knowledge and solutions. And feel free to correct my English grammar and spelling.
Problem
AES in Javascript
I have an encrypted string that I can decrypt with this this Javascript implementation of AES 256 CTR mode
password = "myPassphrase"
ciphertext = "bQJdJ1F2Y0+uILADqEv+/SCDV1jAb7jwUBWk"
origtext = Aes.Ctr.decrypt(ciphertext, password, 256);
alert(origtext)
This decrypts my string and a warning window appears with This is a test Text.
AES with PyCrypto
Now I want to decrypt this string using python and PyCrypto
password = 'myPassphrase'
ciphertext = "bQJdJ1F2Y0+uILADqEv+/SCDV1jAb7jwUBWk"
ctr = Counter.new(nbits=128)
encryptor = AES.new(key, AES.MODE_CTR, counter=ctr)
origtext = encryptor.decrypt(base64.b64decode(ciphertext))
print origtext
. ValueError: AES key must be either 16, 24, or 32 bytes long. , PyCrypto, , , , .
, , :
- AES 256 (?). AES - 128 . 32 ?
- . PyCrypto AES.MODE_CTR. counter(). , PyCrypto. Javascript? , .
- base64. .
- . , .
:
for (var i=0; i<nBytes; i++) {
pwBytes[i] = isNaN(password.charCodeAt(i)) ? 0 : password.charCodeAt(i);
}
python
l = 32
key = key + (chr(0)*(l-len(key)%l))
. ?
A???B??d9= ,?h????'
l = 32
key = 'myPassphrase'
key = key + (chr(0)*(l-len(key)%l))
ciphertext = "bQJdJ1F2Y0+uILADqEv+/SCDV1jAb7jwUBWk"
ctr = Counter.new(nbits=128)
encryptor = AES.new(key, AES.MODE_CTR, counter=ctr)
origtext = encryptor.decrypt(base64.b64decode(ciphertext))
print origtext
Javascript,
[...] nonce 8 , 8 . [...]
, . , , Javascript:
origtext = ""
var ciphertext =Aes.Ctr.encrypt(origtext, password, 256);
alert(ciphertext)
/gEKb+N3Y08= (12 ). 12? 8 + 8 = 16Bytes? , bruteforce python, for i in xrange(0,20): ciphertext[i:] base64.b64decode(ciphertext)[i:]. , , . .
.
Javascript, . , Javascript . , - "".
, PyCrypto , Javascript, Javascript Python?
python, .
, .
, nonce block ? ?