nodejs crypto aes-js aes怎么用

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
您的访问请求被拒绝 403 Forbidden - ITeye技术社区
您的访问请求被拒绝
亲爱的会员,您的IP地址所在网段被ITeye拒绝服务,这可能是以下两种情况导致:
一、您所在的网段内有网络爬虫大量抓取ITeye网页,为保证其他人流畅的访问ITeye,该网段被ITeye拒绝
二、您通过某个代理服务器访问ITeye网站,该代理服务器被网络爬虫利用,大量抓取ITeye网页
请您点击按钮解除封锁&nodejs_Crypto_API之家,最大的中文API社区
当前位置:>API参考大全>>>Crypto
出处:API之家
作者:API之家 阅读:2523次
Stability: 3 - Stable
crypto.createCredentials(details)
crypto.createHash(algorithm)
var filename = process.argv[2]; var crypto = require('crypto'); var fs = require('fs'); var shasum = crypto.createHash('sha1'); var s = fs.ReadStream(filename); s.on('data', function(d) { shasum.update(d); }); s.on('end', function() { var d = shasum.digest('hex'); console.log(d + '
' + filename); });
Class: Hash
hash.update(data, [input_encoding])
hash.digest([encoding])
crypto.createHmac(algorithm, key)
Class: Hmac
hmac.update(data)
hmac.digest([encoding])
crypto.createCipher(algorithm, password)
crypto.createCipheriv(algorithm, key, iv)
Class: Cipher
cipher.update(data, [input_encoding], [output_encoding])
cipher.final([output_encoding])
crypto.createDecipher(algorithm, password)
crypto.createDecipheriv(algorithm, key, iv)
Class: Decipher
decipher.update(data, [input_encoding], [output_encoding])
decipher.final([output_encoding])
crypto.createSign(algorithm)
Class: Signer
signer.update(data)
signer.sign(private_key, [output_format])
crypto.createVerify(algorithm)
Class: Verify
verifier.update(data)
verifier.verify(object, signature, [signature_format])
crypto.createDiffieHellman(prime_length)
crypto.createDiffieHellman(prime, [encoding])
Class: DiffieHellman
diffieHellman.generateKeys([encoding])
puteSecret(other_public_key, [input_encoding], [output_encoding])
diffieHellman.getPrime([encoding])
diffieHellman.getGenerator([encoding])
diffieHellman.getPublicKey([encoding])
diffieHellman.getPrivateKey([encoding])
diffieHellman.setPublicKey(public_key, [encoding])
diffieHellman.setPrivateKey(public_key, [encoding])
crypto.pbkdf2(password, salt, iterations, keylen, callback)
crypto.randomBytes(size, [callback])
// async crypto.randomBytes(256, function(ex, buf) { if (ex) throw ex; console.log('Have %d bytes of random data: %s', buf.length, buf); }); // sync try { var buf = crypto.randomBytes(256); console.log('Have %d bytes of random data: %s', buf.length, buf); } catch (ex) { // handle error }
Ios下的crypto使用方法和示例
上一篇:下一篇:
nodejs Crypto相关文章请点击
责任申明:本站内容均整理自互联网,若有侵权,请联系我们。使用本站提供的任务技术内容造成不良后果,本站不负任何责任。
欢迎投稿,电子邮件:(#号换成@)&& QQ群1: &&javascript - How to decrypt AES ECB using crypto-js - Stack Overflow
to customize your list.
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
J it only takes a minute:
Join the Stack Overflow community to:
Ask programming questions
Answer and help your peers
Get recognized for your expertise
I am trying to send encrypted data from flash (client side) to javascript (running as jscript in asp) on the server side.
There are several javascript Aes libraries, but they are virtually undocumented.
I'm trying with crypto-js, but cant get the code to work.
The below example generates an empty output, it should generate "6bc1bee22e409f96e93d7ea".
&html xmlns="http://www.w3.org/1999/xhtml"&
&script src="http://crypto-/svn/tags/3.1/build/rollups/aes.js"&&/script&
&script src="http://crypto-/svn/tags/3.1/build/components/mode-ecb.js"&&/script&
&script src="http://crypto-/svn/tags/3.1/build/components/pad-nopadding.js"&&/script&
var key = CryptoJS.enc.Hex.parse('2b7e151628aed2a6abff3c');
var data = CryptoJS.enc.Hex.parse('3ad77bb40d7a3660a89ecaf32466ef97');
var decrypted3 = CryptoJS.AES.decrypt(data, key, {mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.NoPadding });
document.write("&br /& dec3: " + decrypted3.toString());
I took a documented working key and encrypted data from
I am using ECB because its the only version which doesn't require an IV or salt, as the server wont know the IV or salt used on the client, so would not be able to decrypt the data.
Does anyone have any clue why the above fails to decrypt the data, or know where any documentation is?
Update: After some hours of trial and error, I came up with a combination which produces the output: 7c121d95aada2ffff1ce3118561eba40555c0b However, this is still incorrect.
The change made to produce this was:
var decrypted3 = CryptoJS.AES.decrypt('3ad77bb40d7a3660a89ecaf32466ef97', key, {mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.NoPadding });
I.e. I passed the data in as a string of hex, which cant be right, but does produce output at least.
The next problem will be padding issues.
On the client I am using AS3 hurlant libraries, which only offer two padding strategies: NONE and PKCS#5.
In crypto-js, the available strategies are:
Pkcs7 (the default)
ZeroPadding
Does this mean there will be no chance to every decrypt data between the two libraries?
Before I have had to write my own padding hacks (between AS3 and java), to add or remove trailing data, but this took days of trial and error with binary data - there must be an easier way to send a single encrypted string from client to server.
SSL is not an option as the client user can simply use Charles proxy or similar to see and tamper with the unencrypted data.
The example below returns the desired output using AES and ECB.
&html xmlns="http://www.w3.org/1999/xhtml"&
&script src="http://crypto-/svn/tags/3.1/build/rollups/aes.js"&&/script&
&script src="http://crypto-/svn/tags/3.1/build/components/mode-ecb.js"&&/script&
&script src="http://crypto-/svn/tags/3.1/build/components/pad-nopadding.js"&&/script&
var encrypted = '3ad77bb40d7a3660a89ecaf32466ef97',
key = CryptoJS.enc.Hex.parse('2b7e151628aed2a6abff3c'),
cipherParams = CryptoJS.lib.CipherParams.create({
ciphertext: CryptoJS.enc.Hex.parse(encrypted)
var decrypted3 = CryptoJS.AES.decrypt(cipherParams, key, {mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.NoPadding });
document.write("&br /& dec3: " + CryptoJS.enc.Hex.stringify(decrypted3));
The only real differences is creating a cypherParams object using CryptoJS.lib.CipherParams.create(). According to the official
a cypherParams object "gives you access to all the parameters used during encryption" including key, iv, salt and the original cypherText. Basically all the info needed to decrypt it. In our case we needed to convert the encrypted data to cypherParam with only the cypherText property. Incidentally the cypherParam can be stringified using standard formats, which is how it is communicated to other systems.
Regarding the padding, as I
it Pkcs7 is an extension of Pkcs5 and should work for any cypher created using Pkcs5. When I tried the code sample above without the NoPadding option (defaulting to Pkcs7) it didn't work, but I can't tell what was used in creating that encrypted data. At least that AES Test Vectors page you linked to doesn't tell us.
Gave up with ECB, tried various permutations with CBC, and got one to work.
It also seems that it is OK to send the IV in plain text from client to server.
Here is the version which correctly outputs "6bc1bee22e409f96e93d7ea".
&html xmlns="http://www.w3.org/1999/xhtml"&
&script src="http://crypto-/svn/tags/3.1/build/rollups/aes.js"&&/script&
&!--script src="http://crypto-/svn/tags/3.1/build/components/mode-cbc.js"&&/script--&
&script src="http://crypto-/svn/tags/3.1/build/components/pad-nopadding.js"&&/script&
var key = CryptoJS.enc.Hex.parse('2b7e151628aed2a6abff3c');
var iv = CryptoJS.enc.Hex.parse('B0C0D0E0F');
var data = CryptoJS.enc.Hex.parse('7649abaccee98e9b12e9197d');
var encrypted = {};
encrypted.key=
encrypted.iv=
encrypted.ciphertext =
var decrypted = CryptoJS.AES.decrypt(encrypted, key, { iv: iv, padding: CryptoJS.pad.NoPadding });
document.write("&br /& dec3: " + CryptoJS.enc.Hex.stringify(decrypted));
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you&#39;re looking for?
Browse other questions tagged
The week&#39;s top questions and answers
Important community announcements
Questions that need answers
By subscribing, you agree to the
Stack Overflow works best with JavaScript enabled}

我要回帖

更多关于 nodejs crypto aes 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信