Skip to content

Instantly share code, notes, and snippets.

@yuiseki
Created June 13, 2013 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuiseki/5772376 to your computer and use it in GitHub Desktop.
Save yuiseki/5772376 to your computer and use it in GitHub Desktop.
# node v0.10.10
crypto = require "crypto"
secretKey = [
0xff, 0x03, 0x44, 0x89, 0xd6, 0xf8, 0x98, 0x21,
0x1f, 0xad, 0xaa, 0xda, 0x39, 0x9d, 0x3f, 0x8e,
0xbc, 0xd5, 0xa1, 0x00, 0xe1, 0x36, 0xfa, 0xcc,
0xe7, 0x48, 0x0a, 0x0e, 0x44, 0x1c, 0xf6, 0xaf,
]
secretKeyBuf = new Buffer(secretKey)
iv = ""
plainEnc = "utf8"
outEnc = "base64"
plainjp = "ニンジャ殺すべし"
plainmix = "ninja殺すべし"
check = (plain) ->
cipher1 = crypto.createCipheriv("rc4", secretKeyBuf, iv)
crypted1 = cipher1.update(plain, plainEnc).toString(outEnc)
console.log plain, crypted1
cipher2 = crypto.createCipheriv("rc4", secretKeyBuf, iv)
crypted2 = cipher2.update(plain, plainEnc, outEnc)
console.log plain, crypted2
console.log crypted1 == crypted2
for plain in [plainjp, plainmix]
check plain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment