AES加密在.NET和解密使用Node.js的密码?

问题描述:

我想在单C#的一些数据进行加密,将其发送到NodeJS服务器和解密它。我试图找出用什么算法来匹配两个。

I'm trying to encrypt some data in Mono C#, send it to a NodeJS server and decrypt it there. I'm trying to figure out what algorithms to use to match the two.

我发送的加密字符串连接codeD使用Base64。所以,我做这样的事情在Javascript中,在那里,我知道这是用来在我的C#应用​​程序中的数据进行加密的密钥:

I send the encrypted string encoded with base64. So I do something like this in Javascript, where I know the key which was used to encrypt the data in my C# application:

var decipher = crypto.createDecipher('aes192',binkey, biniv);
var dec = decipher.update(crypted,'base64','utf8');
dec += decipher.final('utf8');
console.log("dec", dec);

在单创建我的Cypher支架有:

In Mono I create my Cypher with:

using System.Security.Cryptography;
using (Aes aesAlg = Aes.Create("aes192"))

我需要通过正确的字符串Aes.Create(),以便将它使用相同的算法,但我找不到它应该是什么。 AES192是不正确的,似乎。

I need to pass the correct string to Aes.Create() in order to have it use the same algorithm, but I can't find what it should be. "aes192" is not correct it seems.

我不需要AES192这只是一个尝试。推荐不同的加密的味道,如果它是有道理的。安全性是没有太大问题的。

I don't need aes192 this was just a tryout. Suggest a different encryption flavor if it makes sense. Security is not much of an issue.

下面的链接,.NET和Nodejs文档: http://msdn.microsoft.com/en-us /library/system.security.cryptography.aes.aspx http://nodejs.org/api/crypto.html

Here are links to .NET and Nodejs docs: http://msdn.microsoft.com/en-us/library/system.security.cryptography.aes.aspx http://nodejs.org/api/crypto.html

这code适用于我的Node.js的一面,但请更换静态IV,otherwhise AES加密是无用的。

This code works for my Node.js side, but please replace the static iv, otherwhise aes encryption would be useless.

var crypto = require('crypto');

function encrypt(data, key) {
    key = key || new Buffer(Core.config.crypto.cryptokey, 'binary'),
        cipher = crypto.createCipheriv('aes-256-cbc', key.toString('binary'), str_repeat('\0', 16));
    cipher.update(data.toString(), 'utf8', 'base64');
    return cipher.final('base64');
}

function decipher(data, key) {
    key = key || new Buffer(Core.config.crypto.cryptokey, 'binary'),
        decipher = crypto.createDecipheriv('aes-256-cbc', key.toString('binary'), str_repeat('\0', 16));
    decipher.update(data, 'base64', 'utf8');
    return decipher.final('utf8');
}

function str_repeat(input, multiplier) {
    var y = '';
    while (true) {
        if (multiplier & 1) {
            y += input;
        }
        multiplier >>= 1;
        if (multiplier) {
            input += input;
        } else {
            break;
        }
    }
    return y;
}

我希望这可以帮助你。

I hope this helps You.

请注意:您需要提供一个265bit又名32字符键这个算法工作

NOTE: You need to deliver an 265bit aka 32 character key for this algorithm to work.

可能的.NET解决方案:这可以帮助你示例

POSSIBLE .NET SOLUTION: This may help you Example