我有一个生成RC4加密字符串的php函数.我想使用Node解码该字符串 - 理想情况下使用内置的Crypto模块.但我无法这样做 - 我只是得到一个空白字符串.
PHP代码在这里http://code.google.com/p/rc4crypt/
我的JS代码是
crypto = require('crypto');
decipher = crypto.createDecipher("rc4", "MY SECRET KEY");
text = "HELLO";
decrypted = decipher.update(text, "utf8", "hex");
decrypted += decipher.final("hex");
console.log(decrypted);
Run Code Online (Sandbox Code Playgroud)
我没有得到任何输出.我已经使用openssl list-message-digest-algorithms检查了我的OpenSSL实现是否有RC4
我在最新节点OSX 10.8上.
我愿意使用另一个模块来解密 - 我尝试了cryptojs模块,但没有弄清楚如何让它工作 - 当我尝试RC4时给了我错误.
谢谢
我正在尝试使用加密模块在Node.js 和使用Web密码API的Web客户端之间完成密钥交换。
到目前为止,我设法将密钥交换处理到在服务器和客户端上导出共享密钥的程度。在服务器端,我使用了“ secp521r1”曲线,在客户端端,使用了名称为“ P-521”的等效曲线。
在客户端上,我收到一个共享密码,该密码的长度为32个字节,我认为这是256位AES-GCM密钥的正确长度。但是在服务器上,我收到一个长度为66个字节的密钥。以下是生成的密钥的两个示例,一个示例以base64编码,另一个示例为字节数组:
Base64 encoded:
Client AES-Key: AJQQpnOjNe2/QQz5T9NmSPFpFgUG/20739EhdjVt//I=
Server AES-Key: AJQQpnOjNe2/QQz5T9NmSPFpFgUG/20739EhdjVt//LYZ+XeuTgkwv7CJFQrqNWxnny8R+VP3nJuk1SUyDJsa7+f
Byte array:
Client AES-Key: 0,249,8,221,38,57,84,243,202,83,90,68,4,41,49,224,69,89,162,74,47,72,134,169,32,3,133,55,109,105,144,249
Server AES-Key: 0,249,8,221,38,57,84,243,202,83,90,68,4,41,49,224,69,89,162,74,47,72,134,169,32,3,133,55,109,105,144,249,66,66,131,19,81,11,27,161,132,7,244,2,191,221,162,169,247,108,128,229,211,217,109,78,5,71,232,252,243,36,214,42,199,175
Run Code Online (Sandbox Code Playgroud)
我认为我在Node.js上配置错误,但是在文档中找不到有关如何正确执行操作的提示。
这是我在Node.js上提取密钥的操作:
var ecdh = crypto.createECDH('secp521r1');
ecdh.generateKeys();
ecdh.getPublicKey('base64'); // passed this to the client
// After I receive the public key of the client
var shared = ecdh.computeSecret(clientPublicKey, 'base64');
Run Code Online (Sandbox Code Playgroud)
我的问题是:
任何指导表示赞赏。
我正在尝试使用 node.js 加密模块加密文本。
这是代码:
const crypto = require('crypto');
const password = 'password';
const key = crypto.scryptSync(password, 'salt', 24);
const iv = crypto.randomBytes(16);
const cipher = crypto.createCipheriv('aes-256-gcm', key, iv);
var encrypted = cipher.update("Hello", 'utf8', 'hex') + cipher.final('hex');
console.log(encrypted);
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
internal/crypto/cipher.js:103
this[kHandle].initiv(cipher, credential, iv, authTagLength);
^
Error: Invalid key length
[90m at Cipheriv.createCipherBase (internal/crypto/cipher.js:103:19)[39m
[90m at Cipheriv.createCipherWithIV (internal/crypto/cipher.js:121:20)[39m
[90m at new Cipheriv (internal/crypto/cipher.js:225:22)[39m
[90m at Object.createCipheriv (crypto.js:117:10)[39m
at Object.<anonymous> (F:\Misc\App\MySQL-Buzzer-Electron\demo.js:7:23)
[90m at Module._compile (internal/modules/cjs/loader.js:1156:30)[39m
[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)[39m
[90m at Module.load (internal/modules/cjs/loader.js:1000:32)[39m …Run Code Online (Sandbox Code Playgroud) 我有一个在 php 上运行的应用程序,其中使用下面的代码使用 openssl encrption 加密了一些值
<?php
define('OSSLENCKEY','14E2E2D1582A36172AE401CB826003C1');
define('OSSLIVKEY', '747E314D23DBC624E971EE59A0BA6D28');
function encryptString($data) {
$encrypt_method = "AES-256-CBC";
$key = hash('sha256', OSSLENCKEY);
$iv = substr(hash('sha256', OSSLIVKEY), 0, 16);
$output = openssl_encrypt($data, $encrypt_method, $key, 0, $iv);
$output = base64_encode($output);
return $output;
}
function decryptString($data){
$encrypt_method = "AES-256-CBC";
$key = hash('sha256', OSSLENCKEY);
$iv = substr(hash('sha256', OSSLIVKEY), 0, 16);
$output = openssl_decrypt(base64_decode($data), $encrypt_method, $key, 0, $iv);
return $output;
}
echo encryptString("Hello World");
echo "<br>";
echo decryptString("MTZHaEoxb0JYV0dzNnptbEI2UXlPUT09");
?>
Run Code Online (Sandbox Code Playgroud)
我有另一个在 nodejs 上运行的端点,我需要根据上面的 php 加密/解密规则来解密和加密值。我已经搜索过但找不到解决方案。
我尝试使用该库crypto但最终出现错误 …
如何使用crypto模块(服务器端)和crypto-js(客户端,react-native)正确加密/解密node.js之间的数据?
注意:我在 react-native 项目中使用了 cryptojs,因此我不能在客户端上使用加密。更换加密服务器端对我来说不是一个选择。
服务端代码:
var Crypto = require("crypto");
var Cipher = {
pass: "0123456789abcdef0123456789abcdef",
iv: "0123456789abcdef",
encript: function (msg) {
try {
var cipher = Crypto.createCipheriv("aes-256-cbc", this.pass, this.iv);
var hash = cipher.update(msg, 'utf8', "hex");
var hex = hash + cipher.final("hex");
return hex;
} catch (err) {
console.error(err);
return "";
}
},
decript: function (hex){
try {
var decipher = Crypto.createDecipheriv("aes-256-cbc", this.pass, this.iv);
var dec = decipher.update(hex, "hex", 'utf8');
return dec + decipher.final('utf8');
} catch (err) {
console.error(err);
return …Run Code Online (Sandbox Code Playgroud) 我在使用 NodeJS 加密和 crypto.randomBtyes 函数时遇到了一个奇怪的问题。我检测到似乎最近才出现在我的 NodeJS/Typescript 3.2 应用程序中的奇怪行为。
该错误本身就有意义:Cipheriv.createCipherBase 处的密钥长度无效(internal/crypto/cipher.js:79:18)
在检查返回的密钥长度时,它将请求的字节数加倍。我将其表示为“奇怪”,因为它之前有效(截至上周星期四/星期五(3/7/2019 - 3/8/2019)但截至今天早上检测到新行为。但是,我没有t 运行任何更新,所以希望我错过了一些明显的东西。我可以将我的密钥大小更改为我想要的一半,但是,我想在实施黑客之前看看我是否忽略了一些简单的东西。
这是我的加密实现的一个相当基本的例子。
import crypto = require('crypto');
export class Encryption {
static GenerateRandomBytesToHex(size: number): string {
return crypto.randomBytes(size).toString('hex');
}
}
Run Code Online (Sandbox Code Playgroud)
但是在调用时:
let cipherKey = Encryption.GenerateRandomBytesToHex(32);
Run Code Online (Sandbox Code Playgroud)
它返回的是一个 64 个字符的字符串,而不是一个 32 个字符的字符串。
示例:c8a8437677fcfab679f92c8470ffc34b932f5aaa3296c09f652d2becfe1db8b2(长度为64个字符)
这是本文中概述的概念的实现:http : //vancelucas.com/blog/stronger-encryption-and-decryption-in-node-js/
任何帮助将不胜感激。
我正在尝试实现基本的非对称加密;一个服务拥有公钥并使用该公钥加密一个值,然后另一个服务接收加密的消息,使用私钥对其进行解码,并对解密的数据执行某些操作。
\n我遇到的问题是,每次使用内置的crypto.publicEncrypt方法时,我都会返回不同的加密值。据我所知,我使用相同的输入,所以据我了解,我应该看到相同的输出。也许我误解了这一点?
\n这是我的加密实用程序;
\nimport { createPublicKey, createPrivateKey, privateDecrypt, publicEncrypt, constants } from "crypto";\n\nconst privateKeyPem = process.env.ENCRYPTION_PRIVATE_KEY;\nconst privateKeyPemFixed = privateKeyPem.replace(/\\\\n/g, "\\n");\nconst privateKey = createPrivateKey(privateKeyPemFixed);\nconst publicKey = createPublicKey(privateKey);\n\n// const private1 = privateKey.export({\n// type: \'pkcs1\',\n// format: \'pem\',\n// }).toString("base64");\n\n// const public1 = publicKey.export({\n// type: \'pkcs1\',\n// format: \'pem\',\n// }).toString("base64");\n\nexport const encrypt = (text: string): string => {\n const buffer = Buffer.from(text);\n\n const encrypted1 = publicEncrypt( {\n key: publicKey,\n oaepHash: \'sha256\',\n padding: constants.RSA_PKCS1_OAEP_PADDING,\n }, buffer);\n\n const encrypted2 = publicEncrypt({\n key: publicKey,\n …Run Code Online (Sandbox Code Playgroud) 我正在尝试在插入 MongoDB 之前和之后加密和解密值。我正在使用猫鼬模式并调用 get 和 set 方法进行加密和解密。通过调用 set 方法对数据进行加密,但是在从 MongoDB 检索数据时它没有解密。这是我的架构和加密解密方法:
var tempSchema = new Schema({
_id: {type: Schema.ObjectId, auto: true},
name:{type: String},
sample_details:{
_id: false,
objects: [{
object_key:{type: String},
object_value:{type: String, get:decrypt, set:encrypt}
}],
type_params:[{
type_key:{type: String},
type_value:{type: String, get:decrypt, set:encrypt}
}],
test_body:{type: String, get:decrypt, set:encrypt}
}}, {
toObject : {getters: true, setters: true},
toJSON : {getters: true, setters: true}
});
Run Code Online (Sandbox Code Playgroud)
以下是使用的加密和解密方法:
function encrypt(text){
var cipher = crypto.createCipher('aes-256-cbc', secret_key);
var crypted = cipher.update(text,'utf8','hex');
crypted += cipher.final('hex');
return crypted;
} …Run Code Online (Sandbox Code Playgroud) 我目前正在从事一个涉及密码学的 JavaScript 团队项目。
我希望我的程序尽可能安全,如果可能的话达到行业级安全,因此我一直在寻找社区批准的随机大素数生成算法的实现。
我探索了 Node.js Crypto,但没有找到返回随机大概率素数的简单函数。
如何使用 Node.js Crypto 来解决这个问题?
我想加密和解密字符串。我为此使用了 Nodejs 加密。我读过在加密和解密时强烈建议使用 IV。我想将加密数据存储在 MySQL 数据库中,并在需要时对其进行解密。我知道解密过程也需要 IV。但究竟什么是 IV,我应该如何存储它?我读到一些关于 IV 不能保密的内容。这是否意味着我可以将它存储在它所属的加密数据旁边?
node-crypto ×10
node.js ×10
javascript ×5
encryption ×4
cryptography ×2
cryptojs ×2
mongoose ×1
openssl ×1
php ×1
primes ×1
random ×1
rc4-cipher ×1
typescript ×1