Skip to content

Instantly share code, notes, and snippets.

@donpark
Created March 15, 2011 10:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donpark/870585 to your computer and use it in GitHub Desktop.
Save donpark/870585 to your computer and use it in GitHub Desktop.
node.js crypto notes

While this note is useful for achieving compatibility with non-node.js crypto code, it contains implementation details which maybe outdated in the near future. Beware.

key argument

key arguments are expected to be binary strings which is bytes packed as chararacter codes of a string.

What this means is that only lower byte of each character will be used.

crypto.createCipher and crypto.createDecipher

key argument will be hashed using MD5 and resized as needed to generate algorithm specific key bytes and IV.

crypto.createCipheriv and crypto.createDecipheriv

crypto.createCipheriv(algorithm, key, iv)
crypto.createDecipheriv(algorithm, key, iv)

These methods are, as of v0.4.2, undocumented.

iv argument is, like key, expected to be binary string.

Both key and iv arguments will be used as-is, meaning they have to be right size for the requested algorithm. For example, for aes-256-ofb algorithm, key.length should be 32 and iv.length should be 16.

base64 output encoding

As of v0.4.2, base64 output encoding is broken. Use hex or binary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment