我已经有了java加密代码。现在我想使用我的服务器上的 API。即使在尝试了各种教程和示例代码之后,我也无法成功解密哈希值。
我知道固定盐和静脉注射根本不推荐。但为了简单起见并为了理解问题,我将盐和IV保留为“00000000000000000000000000000000”;
Java 加密后的哈希 = "XjxCg0KK0ZDWa4XMFhykIw=="; 使用的私钥=“Mayur12354673645”
有人可以帮我使用 dart 解密上面的字符串吗?
JAVA代码
public String encrypt(String salt, String iv, String passphrase,
String plaintext) {
try {
SecretKey key = generateKey(salt, passphrase);
byte[] encrypted = doFinal(Cipher.ENCRYPT_MODE, key, iv, plaintext
.getBytes("UTF-8"));
return base64(encrypted);
} catch (UnsupportedEncodingException e) {
throw fail(e);
}
}
public String decrypt(String salt, String iv, String passphrase,
String ciphertext) {
try {
SecretKey key = generateKey(salt, passphrase);
byte[] decrypted = doFinal(Cipher.DECRYPT_MODE, key, iv,
base64(ciphertext));
return new String(decrypted, "UTF-8");
} catch …Run Code Online (Sandbox Code Playgroud) 我必须在 nodejs 中使用 aes-128-ecb 加密数据,我的代码是
我正在使用 Crypto 来加密数据
const crypto = require('crypto');
const secret = '1000060000000000';
const cipher = crypto.createCipher('aes-128-ecb', secret);
const ciphertext = cipher.update('9', 'utf8', 'base64')+cipher.final('base64');
console.log("Cipher text is: " + ciphertext);
Run Code Online (Sandbox Code Playgroud)
输出应该是,EtgITaHs6lEvEHBipj08Kg==
但输出是nNzqejauQBnfiDqznGhZ0Q==
我有一个 AWS RDS Aurora PostgreSQL 集群,其中包含四个实例,并在生产中提供多可用区部署。此集群上尚未启用静态加密。现在我必须在这个现有集群上启用加密。AWS 文档建议我创建该集群的快照,然后在启用加密的情况下再次恢复该集群。参考:这里
由于我的集群正在生产中运行,因此我不能接受任何停机或 I/O 暂停。在计划加密现有集群之前,我希望回答以下一些问题:
我正在尝试在 NodeJS (Electron) 中创建一个应用程序作为跨平台桌面应用程序。这将与 iOS 上使用 SWIFT 开发的移动应用程序配对。作为共享数据的一部分,它使用 AES-256-GCM 算法进行加密。我在 SWIFT 中有以下加密和解密方法:
//listItems is an array of the following structure:
// - id: Int, title: String, data: String, ldate: String
func encrypt(listItems: [ListItem], pass: String) -> String{
let encoder = JSONEncoder()
do{
let data = try encoder.encode(listItems)
let key = SymmetricKey(data: SHA256.hash(data: pass.data(using: .utf8)!))
let iv = AES.GCM.Nonce()
let sealedBox = try AES.GCM.seal(data, using: key, nonce: iv)
return sealedBox.combined?.base64EncodedData()
}catch{
fatalError("Couldn't encrypt data\(error)")
}
}
func decrypt(data: Data, pass: String) …Run Code Online (Sandbox Code Playgroud) 我正在从 Web 服务 API 接收请求中的 XML。它包含一个由请求者的私钥签名的签名,我必须通过请求者的公钥对其进行验证。然后我必须发送带有签名的响应,由我的私钥签名。
此过程应使用 PHP 中的 RSA 和 SHA-256 来完成。
我目前有以下代码:
$data_to_encrypt = "MsgBody..../MsgBody"; // xml
$msgbody = simplexml_load_string($data_to_encrypt);
$result = $msgbody->xpath('//MsgBody');
openssl_private_encrypt(json_encode($result), $encrypted, $private_key, OPENSSL_PKCS1_PADDING);
$signature = $encrypted;
$verify = openssl_verify($encrypt, $signature ,$publick_key, OPENSSL_ALGO_SHA256);
Run Code Online (Sandbox Code Playgroud)
$verify的结果= 0。为什么这是一个错误的验证?
我想在 Python 3.8.5 上使用 AES 256 为我的明文编写加密,但是当我执行它时,我收到错误ValueError:不正确的 AES 密钥长度(64 字节)我的代码中是否有问题?
plaintext = "ABC123"
secret_key = "6789045129812345"
secret_iv = "4567891122315731"
key = hashlib.sha256(str(secret_key).encode('utf-8')).hexdigest()
iv = hashlib.sha256(str(secret_iv).encode('utf-8')).hexdigest()
substring_iv = iv[:16]
cipher_config = AES.new(key.encode("utf-8"), AES.MODE_CBC, substring_iv.encode("utf-8"))
results = base64.b64encode(cipher_config)
print("results : "+results)
Run Code Online (Sandbox Code Playgroud) 我正在尝试解密存储在数据库中的数据,然后再将其发送到客户端。
我正在使用带有 AES-256-GCM 加密的内置加密模块。
我已成功实现加密并且工作正常,我的问题是我正在尝试解密不同文件中的数据,但我不断收到错误。
这是错误:
(node:35798) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "iv" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
1.js
router.post(
"/",
async(req, res) => {
function getFullAddress({housenumber, address1, address2, city, postcode, country}) {
return [housenumber, address1, ...(address2 ? [address2]: []), city, postcode, country].join(", ");
}
const aes256gcm = (key) => {
const encrypt = (str) => {
const iv = new crypto.randomBytes(16);
const cipher = crypto.createCipheriv('aes-256-gcm', key, iv);
let enc …Run Code Online (Sandbox Code Playgroud) 我正在使用 node-rsa 包通过 RSA 函数进行非对称加密。
目前,我正在生成我的公钥和私钥,如下所示:
generateKeys = function() {
const key = new NodeRSA({ b: 1024 });
return {
public: key.exportKey('public'),
private: key.exportKey('private'),
}
}
Run Code Online (Sandbox Code Playgroud)
有没有可能的方法从给定的字符串生成密钥?我想这样做,以便我的用户可以轻松写下他们的私钥,这对我的项目很重要。毕竟,写下 1024 个字符长的私钥几乎是不可能的。
我希望有这样的事情:
const key = new NodeRSA({ b: 1024 }, "Secret goes here")
Run Code Online (Sandbox Code Playgroud)
我认为这可能是可能的,因为 sha256 函数可以接受任何字符串进行哈希。我知道 RSA 加密并不是真正的哈希函数,所以我不确定是否可以达到相同的效果。
任何帮助表示赞赏!
所以我试图实现一些方法来加密然后解密一些数据。我对此没有任何经验,并且我尝试按照网上的一些帖子了解如何进行此操作。
\n当我将加密的“hello”传递给解密函数时,我得到:
\nlet a = importPublicKeyAndEncrypt('hello')\n\nCryptoKey\xc2\xa0{type: "public", extractable: true, algorithm: {\xe2\x80\xa6}, usages: Array(1)} W29iamVjdCBBcnJheUJ1ZmZlcl0=\n\nimportPrivateKeyAndDecrypt(a)\nPromise\xc2\xa0{<pending>}\n\nDOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.\nat importPrivateKeyAndDecrypt (<anonymous>:26:60)\nRun Code Online (Sandbox Code Playgroud)\n当我使用我在 PKCS#8 看到的一篇帖子中的加密消息时,解密功能可以正常工作,但当我生成自己的密钥时,解密功能就不能正常工作。
\n这是代码\n我做错了什么?
\n// PEM encoded X.509 key\nconst publicKey = `\n-----BEGIN PUBLIC KEY-----\n <removed for space>\n-----END PUBLIC KEY-----`;\n\n// PEM encoded PKCS#8 key\nconst privateKey = `\n-----BEGIN PRIVATE KEY-----\n <removed for space>\n-----END PRIVATE KEY-----`;\n\nasync function importPublicKeyAndEncrypt(str) {\n try {\n const pub = await importPublicKey(publicKey);\n console.log(pub);\n …Run Code Online (Sandbox Code Playgroud) 我有一些使用 SubtleCrypto 的代码来加密密钥并将其存储在数据库中。
对于另一个功能,我必须能够在 Node 12 中对其进行加密。如果没有 SubtleCrypto,我必须在 Crypto 中重新创建该功能。
我得到相同大小的输出,但它似乎无法被 SubtleCrypto 解密,我试图找出哪里出了问题。
这是在浏览器上使用 SubtleCrypto 运行的代码:
key = getKeyMaterial(password)];
salt = base64ToArraybuffer(optionalSalt)
aesKey = crypto.subtle.deriveKey(
{
name: constants.algorithms.pbkdf2,
salt: salt,
iterations: pbkdf2Iterations,
hash: { name: constants.hash.sha256 },
},
key,
{
name: constants.algorithms.aesGcm,
length: aesWrapKeyBitsLength,
},
true,
['wrapKey', 'unwrapKey']
),
return {
salt: arraybufferTobase64(salt),
aesKey: aesKey,
}
function getKeyMaterial(password) {
var enc = new TextEncoder();
crypto.subtle.importKey(
constants.format.raw,
enc.encode(password),
{
name: constants.algorithms.pbkdf2,
},
false,
['deriveKey']
)
Run Code Online (Sandbox Code Playgroud)
如果没有 SubtleCrypto,在 Node 12 中,我被迫使用 Crypto …
encryption ×10
node.js ×5
aes ×3
rsa ×3
cryptojs ×2
javascript ×2
subtlecrypto ×2
amazon-rds ×1
cbc-mode ×1
dart ×1
flutter ×1
hash ×1
node-crypto ×1
php ×1
python ×1
sha256 ×1
swift ×1