Created
July 13, 2011 03:51
-
-
Save drdaeman/1079679 to your computer and use it in GitHub Desktop.
node.js crypto is broken
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env coffee | |
crypto = require "crypto" | |
# | |
# Rijndael128 test vector, ecb_tbl.txt, KEYSIZE=128, "ecb-tbl-128: I=1" | |
# - plaintext = 506812a45f08c889b97f5980038b8359 | |
# - ciphertext = d8f532538289ef7d06b506a4fd5be9c9 | |
# - key = 00010203050607080a0b0c0d0f101112 | |
# | |
c = crypto.createCipher "aes-128-ecb", new Buffer("00010203050607080a0b0c0d0f101112", "hex").toString "binary" | |
s = c.update new Buffer("506812a45f08c889b97f5980038b8359", "hex").toString "binary" | |
s += c.final() | |
# Expected: d8f532538289ef7d06b506a4fd5be9c9 | |
# Actual result: 357b9018178ee4123697013fe65d24be2d395194e71b5ce17251443a58cbb3a1 | |
console.log new Buffer(s, "binary").toString "hex" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Rijndael128 test vector, ecb_tbl.txt, KEYSIZE=128, "ecb-tbl-128: I=1" | |
# - plaintext = 506812a45f08c889b97f5980038b8359 | |
# - ciphertext = d8f532538289ef7d06b506a4fd5be9c9 | |
# - key = 00010203050607080a0b0c0d0f101112 | |
# | |
# Expected and actual result: d8f532538289ef7d06b506a4fd5be9c9% | |
# | |
echo "506812a45f08c889b97f5980038b8359" \ | |
| perl -pe 's/(..)/chr hex $1/eg;' \ | |
| openssl enc -aes-128-ecb -K "00010203050607080a0b0c0d0f101112" -nopad \ | |
| hexdump -e '/1 "%02x"' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from Crypto.Cipher import AES | |
import binascii | |
# | |
# Rijndael128 test vector, ecb_tbl.txt, KEYSIZE=128, "ecb-tbl-128: I=1" | |
# - plaintext = 506812a45f08c889b97f5980038b8359 | |
# - ciphertext = d8f532538289ef7d06b506a4fd5be9c9 | |
# - key = 00010203050607080a0b0c0d0f101112 | |
# | |
# Expected and actual result: d8f532538289ef7d06b506a4fd5be9c9% | |
# | |
c = AES.new(binascii.unhexlify("00010203050607080a0b0c0d0f101112"), AES.MODE_ECB) | |
print(binascii.hexlify(c.encrypt(binascii.unhexlify("506812a45f08c889b97f5980038b8359")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment