Skip to content

Instantly share code, notes, and snippets.

@goonoo
Last active August 29, 2015 14:12
Show Gist options
  • Select an option

  • Save goonoo/8f93059fee71f483eaae to your computer and use it in GitHub Desktop.

Select an option

Save goonoo/8f93059fee71f483eaae to your computer and use it in GitHub Desktop.
Performance test between RC4 and AES128 and AES256
crypto = require('crypto')
cipher_key = "awegohaewiot2#%@#A#()GAWJVZDz34t#$TJOP#A$TA"
cipher = (txt) ->
c = crypto.createCipher('aes-256-cbc', cipher_key)
crypted = c.update(txt, 'utf8', 'hex')
crypted += c.final('hex')
return crypted
decipher = (crypted) ->
d = crypto.createDecipher('aes-256-cbc', cipher_key)
try
txt = d.update(crypted, 'hex', 'utf8')
txt += d.final('utf8')
catch e
txt = null
return txt
obj = {a:1, b:2, c:['awefawfe','awegawegaweg','awefawefawef',123124125,3463874598217353], d:'a'}
text = JSON.stringify obj
encrypted = cipher text
# encrypt test
s = new Date().valueOf()
run = ->
cipher text
for i in [0...100000]
run()
e = new Date().valueOf()
console.log "encrypt: #{e - s}"
# decrypt test
s = new Date().valueOf()
run = ->
decipher encrypted
for i in [0...100000]
run()
e = new Date().valueOf()
console.log "decrypt: #{e - s}"
process.exit 0
crypto = require('crypto')
cipher_key = "awegohaewiot2#%@#A#()GAWJVZDz34t#$TJOP#A$TA"
cipher = (txt) ->
c = crypto.createCipher('rc4', cipher_key)
crypted = c.update(txt, 'utf8', 'hex')
crypted += c.final('hex')
return crypted
decipher = (crypted) ->
d = crypto.createDecipher('rc4', cipher_key)
try
txt = d.update(crypted, 'hex', 'utf8')
txt += d.final('utf8')
catch e
txt = null
return txt
obj = {a:1, b:2, c:['awefawfe','awegawegaweg','awefawefawef',123124125,3463874598217353], d:'a'}
text = JSON.stringify obj
encrypted = cipher text
# encrypt test
s = new Date().valueOf()
run = ->
cipher text
for i in [0...100000]
run()
e = new Date().valueOf()
console.log "encrypt: #{e - s}"
# decrypt test
s = new Date().valueOf()
run = ->
decipher encrypted
for i in [0...100000]
run()
e = new Date().valueOf()
console.log "decrypt: #{e - s}"
process.exit 0
@goonoo
Copy link
Copy Markdown
Author

goonoo commented Dec 30, 2014

10회 테스트

rc4

encrypt: 1664 decrypt: 1811
encrypt: 1662 decrypt: 1831
encrypt: 1649 decrypt: 1857
encrypt: 1646 decrypt: 1853
encrypt: 1653 decrypt: 1828
encrypt: 1657 decrypt: 1818
encrypt: 1662 decrypt: 1836
encrypt: 1629 decrypt: 1843
encrypt: 1653 decrypt: 1819
encrypt: 1653 decrypt: 1809

aes128

encrypt: 1799 decrypt: 1963
encrypt: 1796 decrypt: 1949
encrypt: 1757 decrypt: 2009
encrypt: 1775 decrypt: 1987
encrypt: 1804 decrypt: 1977
encrypt: 1787 decrypt: 1969
encrypt: 1795 decrypt: 1962
encrypt: 1777 decrypt: 1977
encrypt: 1769 decrypt: 1976
encrypt: 1794 decrypt: 1969

aes256

encrypt: 1864 decrypt: 2006
encrypt: 1875 decrypt: 1998
encrypt: 1852 decrypt: 2016
encrypt: 1860 decrypt: 1989
encrypt: 1874 decrypt: 1993
encrypt: 1852 decrypt: 1993
encrypt: 1875 decrypt: 1998
encrypt: 1880 decrypt: 1996
encrypt: 1850 decrypt: 1998
encrypt: 1886 decrypt: 1982

요약: RC4가 AES128 대비 1.08배, AES256 대비 1.13배 정도 빠름

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