相关疑难解决方法(0)

加密/解密在两个不同的openssl版本之间不能很好地工作

我已经下载并编译了openssl-1.1.0.

我可以加密,并使用相同的exe解密openssl(如这里)

me@ubuntu:~/openssl-1.1.0$ LD_LIBRARY_PATH=. ./apps/openssl aes-256-cbc -a -salt -in file.txt -out file.txt.enc
enter aes-256-cbc encryption password: 123
Verifying - enter aes-256-cbc encryption password:
me@ubuntu:~/openssl-1.1.0$ LD_LIBRARY_PATH=. apps/openssl aes-256-cbc -a -d -in file.txt.enc -out file.txt.dec
enter aes-256-cbc decryption password: 123
Run Code Online (Sandbox Code Playgroud)

openssl用于:libcrypto.so.1.1, libssl.so.1.1

当我尝试openssl使用我的ubuntu上安装的解密时,它使用: /lib/x86_64-linux-gnu/libssl.so.1.0.0, /lib/x86_64-linux-gnu/libcrypto.so.1.0.0

我收到一个错误:

me@ubuntu:~/openssl-1.1.0$ openssl aes-256-cbc -a -d -in file.txt.enc -out file.txt.dec2
enter aes-256-cbc decryption password: 123
bad decrypt
140456117421728:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:evp_enc.c:539:
Run Code Online (Sandbox Code Playgroud)

可能是什么原因导致的 谢谢

linux encryption openssl cryptography libssl

30
推荐指数
1
解决办法
1万
查看次数

使用node.js解密AES256会返回错误的最终块长度

使用此Gist,我能够在Node.js 0.8.7中成功解密AES256.然后当我升级到Node.js 0.10.24时,我现在看到这个错误:

TypeError:错误:0606506D:数字包络例程:EVP_DecryptFinal_ex:
Decipheriv.Cipher.final中的最终块长度错误(crypto.js:292:27)

以下是Gist的解密代码(为方便起见,此处显示):

var crypto = require('crypto');

var AESCrypt = {};

AESCrypt.decrypt = function(cryptkey, iv, encryptdata) {
encryptdata = new Buffer(encryptdata, 'base64').toString('binary');

var decipher = crypto.createDecipheriv('aes-256-cbc', cryptkey, iv),
decoded = decipher.update(encryptdata);

decoded += decipher.final();
return decoded;
}

AESCrypt.encrypt = function(cryptkey, iv, cleardata) {
var encipher = crypto.createCipheriv('aes-256-cbc', cryptkey, iv),
encryptdata = encipher.update(cleardata);

encryptdata += encipher.final();
encode_encryptdata = new Buffer(encryptdata, 'binary').toString('base64');
return encode_encryptdata;
}

var cryptkey = crypto.createHash('sha256').update('Nixnogen').digest(),
iv = 'a2xhcgAAAAAAAAAA',
buf = "Here is some …
Run Code Online (Sandbox Code Playgroud)

encryption openssl aes node.js

13
推荐指数
3
解决办法
3万
查看次数

与NodeJ和mbedtls一起使用的加密程序

首先,让我首先说明我不是一个密码学家,我也不擅长编写c代码,所以如果这个问题的答案显而易见或得到回答,请原谅.我正在开发一个消息传递程序,不能在目标平台上使用TLS.因此,我需要找到一种使用对称预共享密钥密码(如AES)加密每条消息的方法.

我正在寻找一种方法来加密和解密一端的mbedtls程序(例如aescrypt2)和另一端的nodejs程序之间的数据.Mbedtls,以前的polarssl,是一个为嵌入式设备提供加密的库.源代码中包含一些示例程序,如aescrypt2,rsaencrypt,ecdsa和crypt_and_hash.

当使用aescrypt2对生成的加密数据进行解密时,Aescrypt2工作正常,但我似乎无法使用aescrypt加密数据,使用nodejs加密或任何其他程序解密,包括openssl.例如:

echo 'this is a test message' >test.txt
aescrypt 0 test.txt test.out hex:E76B2413958B00E193
aescrypt 1 test.out test.denc hex:E76B2413958B00E193
cat test.denc
this is a test message
Run Code Online (Sandbox Code Playgroud)

使用openssl:

openssl enc -in out.test -out outfile.txt -d -aes256 -k E76B2413958B00E193
bad magic number
Run Code Online (Sandbox Code Playgroud)

一些当前不起作用的示例节点代码

    var crypto = require('crypto');
    var AESCrypt = {};

AESCrypt.decrypt = function(cryptkey, iv, encryptdata) {
    encryptdata = new Buffer(encryptdata, 'base64').toString('binary');

    var decipher = crypto.createDecipheriv('aes-256-cbc', cryptkey, iv),
        decoded = decipher.update(encryptdata, 'binary', 'utf8');

    decoded += decipher.final('utf8');
    return decoded;
} …
Run Code Online (Sandbox Code Playgroud)

c aes node.js

5
推荐指数
1
解决办法
533
查看次数

为什么我不能使用openssl加密的NodeJS解密文件?

我使用命令行加密文件

openssl aes-256-cbc -in /tmp/text.txt -out /tmp/text.crypt
Run Code Online (Sandbox Code Playgroud)

我然后尝试使用以下JavaScript代码解密它:

crypto        = require( 'crypto' );
cipher_name   = 'aes-256-cbc';
password      = '*';
decoder       = crypto.createDecipher( cipher_name, password );
text_crypt    = njs_fs.readFileSync( '/tmp/text.crypt' );
chunks        = [];
chunks.push decoder.update( text_crypt, 'binary' );
chunks.push decoder.final( 'binary' );
text          = chunks.join( '' ).toString( 'utf-8' );
Run Code Online (Sandbox Code Playgroud)

这失败了

TypeError: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

encryption node.js

4
推荐指数
1
解决办法
4480
查看次数

解密AES256密码时出现错误“错误的最终块长度”

在使用 AES 加密和解密时,我正面临着本线程中提到的完全相同的问题。

crypto.js:202
var ret = this._handle.final(); ^ 错误:错误:0606506D:数字信封例程:EVP_DecryptFinal_ex: Decipher.Cipher.final (crypto.js:202:26)
处错误(本机)的最终块长度错误

这些是我的加密和解密功能:

var config = {
cryptkey: crypto.createHash('sha256').update('Nixnogen').digest(),
iv: "a2xhcgAAAAAAAAAA"
};

function encryptText(text){
    console.log(config.cryptkey);
        var cipher = crypto.createCipheriv('aes-256-cbc', config.cryptkey, config.iv);
        var crypted = cipher.update(text,'utf8','binary');
        crypted += cipher.final('binary');
    crypted = new Buffer(crypted, 'binary').toString('base64');
        return crypted;
}

function decryptText(text){
    console.log(config.cryptkey);
        if (text === null || typeof text === 'undefined' || text === '') {return text;};
    text = new Buffer(text, 'base64').toString('binary');
        var decipher = crypto.createDecipheriv('aes-256-cbc', config.cryptkey, config.iv);
        var dec …
Run Code Online (Sandbox Code Playgroud)

encryption cryptography aes mongoose node.js

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

encryption ×4

node.js ×4

aes ×3

cryptography ×2

openssl ×2

c ×1

libssl ×1

linux ×1

mongoose ×1