Tag: cryptography

node.js中STARTTLS的特定TLS版本

如何用tls.createSecurePair或crypto.createCredentials指定TLS版本? 我在问b / c我想添加STARTTLS服务器支持到这个starttls节点库 。

从密码导出节点密码密钥会导致与浏览器不同的结果

我试图在浏览器中重新创buildSymfony的MessageDigestPasswordEncoder 。 我有一些与browserify和encryption模块的问题。 我尝试用JavaScript生成哈希,但没有节点。 这是我的代码与节点: var crypto = require('crypto'); var encodePassword = function (raw, salt) { var salted = raw + '{'+salt+'}', hash = crypto.createHash('sha512').update(salted, 'utf-8'); for (var i = 1; i < 5000 ; i++) { hash = crypto.createHash('sha512').update(hash.digest('binary')+salted); } return hash.digest('base64'); }; console.log(encodePassword("admin", "81b6zjhf64w8kogsgkgw804ss8gc0w0")); 它返回: qmNs3bqtTeoS4uRq2Chh1fUNPu+lzn3KR7mWFHAq5NEPrK0QZ9XkLDUniZ39uosnozNrPL7mByzUZ/A19Io4sQ== 现在,考虑到我需要实现这个没有节点,我用了browserify browserify index.js > crypto.js 我创build了一个testing页面,其中包括: <script […]

TripleDes CBC Nodejs实现问题

我需要在NodeJs中复制http://tripledes.online-domain-tools.com/中的3DS CBCencryption结果。 这是我的代码: const crypto = require('crypto'); const cipher = crypto.createCipher('des-ede3-cbc', key); password = Buffer.from('MYPASS', 'utf8'); let encrypted = [cipher.update(password)]; encrypted.push(cipher.final()); encrypted = Buffer.concat(encryptedArr); console.log(encrypted.toString('hex')); tripledes.online-domain-tools.com的结果是: 注意结果应该是59 30 20 02 a5 8c dd 5e,但是我的代码给了我33 97 d8 b0 e3 00 d1 53。 我错过了什么? 编辑2:按照你的build议,我改变了我的代码(还添加了一些与NIST出版物的指导进行的testing): const crypto = require('crypto'); function encrypt (inputkey, keyformat, password, passwordformat) { let […]

加解密错误

为什么下面的代码在encryption中抛出DecipherFinal错误 – var crypto = require('crypto'); c=new Date; x= (c.getTime()+"."+c.getMilliseconds()).toString()+".uIn"; key = 'sevsolut' , plaintext = x , cipher = crypto.createCipher('aes-256-cbc', key) , decipher = crypto.createDecipher('aes-256-cbc', key); cipher.update(plaintext, 'utf8', 'base64'); var encryptedPassword = cipher.final('base64') decipher.update(encryptedPassword, 'base64', 'utf8'); var decryptedPassword = decipher.final('utf8'); console.log('encrypted :', encryptedPassword); console.log('decrypted :', decryptedPassword);

如何解密CryptoJS中的AES 128(nodejs / web浏览器)

我正在使用一个nodejs服务器,并且我使用encryption节点模块成功地在Base64中encryption/解密(使用IV&Key)一个json。 然而,当我发送与我的AES 128 CTR json发射行动到一个web客户端,我收到正确的我的json base64数据encryption,但我的问题是当我不想解密这个。 在CryptoJS文档中,我find了这样一个例子: var text = "Hello world"; var key = CryptoJS.enc.Base64.parse("myKey"); var iv = CryptoJS.enc.Base64.parse("myIv"); var encrypted = CryptoJS.AES.encrypt(text, key, {iv: iv}); console.log(encrypted); // print something like that s {init: function, $super: s, ciphertext: l.WordArray.t.extend.init, key: s, iv: s…} var decrypted = CryptoJS.AES.decrypt(encrypted, key, {iv: iv}); console.log(decrypted.toString(CryptoJS.enc.Utf8)); // print Hello […]

如何在javascript中创buildHMAC

我绑定在nodejs中使用java函数作为参考实现hmac函数。 这是我需要模拟的Java函数: private static String printMacAsBase64(byte[] macKey, String counter) throws Exception { // import AES 128 MAC_KEY SecretKeySpec signingKey = new SecretKeySpec(macKey, "AES"); // create new HMAC object with SHA-256 as the hashing algorithm Mac mac = Mac.getInstance("HmacSHA256"); mac.init(signingKey); // integer -> string -> bytes -> encrypted bytes byte[] counterMac = mac.doFinal(counter.getBytes("UTF-8")); // base 64 […]

节点js – 使用由SmartCard HSM和NodeRSA模块生成的密钥

我使用模块pkcs11js来生成具有智能卡HSM的RSA密钥,如示例#3所示 。 var publicKeyTemplate = [ { type: pkcs11js.CKA_CLASS, value: pkcs11js.CKO_PUBLIC_KEY }, { type: pkcs11js.CKA_TOKEN, value: false }, { type: pkcs11js.CKA_LABEL, value: "My RSA Public Key" }, { type: pkcs11js.CKA_PUBLIC_EXPONENT, value: new Buffer([1, 0, 1]) }, { type: pkcs11js.CKA_MODULUS_BITS, value: 2048 }, { type: pkcs11js.CKA_VERIFY, value: true } ]; var privateKeyTemplate = [ { type: […]

HMAC签名与github中的x-hub-signature不匹配

我正在处理来自github的传入Webhook,并且想要validationx-hub-signature。 我使用hmac来散列“秘密”,然后比较这两个哈希值。 问题是他们从来不匹配。 这是我的设置: router.route("/auth") .post((req, res) => { var hmac = crypto.createHmac("sha1", process.env.WEBHOOK_SECRET); var calculatedSignature = "sha1=" + hmac.update(JSON.stringify(req.body)).digest("hex"); console.log(req.headers["x-hub-signature"] === calculatedSignature); // Returns false console.log(req.headers["x-hub-signature"]) // => sha1=blablabla console.log(calculatedSignature) // => sha1=foofoofoo res.end(); }); 我已经尝试了一切,但不能使它工作。 想知道如果hmac.update()应该保存另一个参数比JSON.stringify(req.body) 。 有谁知道他们为什么不匹配?

AES在.NET中encryption并使用Node.jsencryption解密?

我试图encryptionMono C#中的一些数据,将其发送到NodeJS服务器并在那里解密。 我想弄清楚使用什么algorithm来匹配这两个。 我发送用base64编码的encryptionstring。 所以我在JavaScript中做了这样的事情,我知道用于encryption我的C#应用​​程序中的数据的密钥: var decipher = crypto.createDecipher('aes192',binkey, biniv); var dec = decipher.update(crypted,'base64','utf8'); dec += decipher.final('utf8'); console.log("dec", dec); 在单声道我创build我的Cypher: using System.Security.Cryptography; using (Aes aesAlg = Aes.Create("aes192")) 我需要将正确的string传递给Aes.Create(),以使它使用相同的algorithm,但是我找不到它应该是什么。 看起来“aes192”是不正确的。 我不需要aes192这只是一个试用。 build议一个不同的encryption风格,如果它是有道理的。 安全不是一个问题。 这里是链接到.NET和Nodejs文档: http : //msdn.microsoft.com/en-us/library/system.security.cryptography.aes.aspx http://nodejs.org/api/crypto.html

Rfc2898DeriveBytes在javascript中的等价物?

我已经看到C#代码可以使用如下代码encryption和解密密码: http://wp7-travel.googlecode.com/svn/trunk/SilverlightPhoneDatabase/Cryptography.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Security.Cryptography; using System.IO; using System.Reflection; namespace SilverlightPhoneDatabase { /// <summary> /// Class used to encrypt the database /// </summary> public static class Cryptography { /// <summary> /// Incrypt the input using password provided /// </summary> /// <param name="input">Input string to encrypt</param> /// <param name="password">Password […]