相关疑难解决方法(0)

使用PyCrypto AES进行Python加密

我今天刚刚找到了pycrypto,我一直在研究我的AES加密类.不幸的是,只有一半的工作.self.h.md5以十六进制格式输出md5哈希值,为32byte.这是输出.它似乎解密了消息,但它在解密后放置了随机字符,在这种情况下\n \n \n ...我认为我的self.data块大小有问题,有谁知道如何解决这个问题?

Jans-MacBook-Pro:test2 jan $ ../../bin/python3 data.py b'RLfGmn5jf5WTJphnmW0hXG7IaIYcCRpjaTTqwXR6yiJCUytnDib + GQYlFORm + jIctest 1 2 3 4 5 endtest \n \n \n \n \n \n \n \n \n \n"

from Crypto.Cipher import AES
from base64 import b64encode, b64decode
from os import urandom

class Encryption():
    def __init__(self):
        self.h = Hash()

    def values(self, data, key):
        self.data = data
        self.key = key
        self.mode = AES.MODE_CBC
        self.iv = urandom(16)
        if not self.key:
            self.key = Cfg_Encrypt_Key
        self.key = self.h.md5(self.key, True)

    def encrypt(self, data, key): …
Run Code Online (Sandbox Code Playgroud)

python pycrypto

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

使用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万
查看次数

在节点中加密并在java中解密

我有一个Java加密代码.我正在尝试将加密部分移植到节点.基本上,节点将使用加密模块进行加密,然后Java将进行解密.

以下是我在Java中进行加密的方法:

protected static String encrypt(String plaintext) {
    final byte[] KEY = {
            0x6d, 0x79, 0x56, 0x65, 0x72, 0x79, 0x54, 0x6f, 0x70,
            0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x4b
    };

    try {
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
        final SecretKeySpec secretKey = new SecretKeySpec(KEY, "AES");
        cipher.init(Cipher.ENCRYPT_MODE, secretKey);
        final String encryptedString = Base64.encodeToString(
            cipher.doFinal(plaintext.getBytes()), Base64.DEFAULT);

        return encryptedString;
    } catch (Exception e) {
        return null;
    }
}
Run Code Online (Sandbox Code Playgroud)

以下是我在节点中进行加密的方法:

var crypto = require('crypto'),
    key = new Buffer('6d7956657279546f705365637265744b', 'hex'),
    cipher = crypto.createCipher('aes-128-ecb', key),
    chunks = []; …
Run Code Online (Sandbox Code Playgroud)

java encryption openssl aes node.js

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

Node.js - 在加密模块中设置填充

我一直在查看Node中加密模块的文档,我正在试图弄清楚在进行对称加密时如何设置填充.我正在尝试使用带有PKCS5填充的AES-128-ECB.

我无法看到它允许您指定填充的任何地方.我当然希望这可以使用这个库.如何在加密模块中为对称加密指定填充?

cryptography node.js node-crypto

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