简体   繁体   English

Java 的 RSA/ECB/OAEPWithSHA-256AndMGF1Padding 在 Node.js 中的等价物

[英]Java's RSA/ECB/OAEPWithSHA-256AndMGF1Padding equivalent in Node.js

The data decryption will run in JAVA using RSA/ECB/OAEPWithSHA-256AndMGF1Padding algorithm.数据解密将使用RSA/ECB/OAEPWithSHA-256AndMGF1Padding算法在 JAVA 中运行。 So I have to encrypt the data with public key using the algorithm equivalent to RSA/ECB/OAEPWithSHA-256AndMGF1Padding in node.js .因此,我必须使用等效于node.jsRSA/ECB/OAEPWithSHA-256AndMGF1Padding的算法使用公钥加密数据。

I tried with crypto.publicEncrypt(key, buffer) which uses crypto.constants.RSA_PKCS1_OAEP_PADDING which is not similar to the above algorithm.我尝试使用crypto.publicEncrypt(key, buffer) ,它使用与上述算法不相似的 crypto.constants.RSA_PKCS1_OAEP_PADDING 。 So I need algorithm equivalent to "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" or how to achieve the same in node.js所以我需要等同于“RSA/ECB/OAEPWithSHA-256AndMGF1Padding”的算法或者如何在 node.js 中实现相同的算法

I finally found the answer.我终于找到了答案。 Equivalent to "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" can be achieved via node-forge npm module.相当于“RSA/ECB/OAEPWithSHA-256AndMGF1Padding”可以通过node-forge npm模块实现。 https://www.npmjs.com/package/node-forge#rsa https://www.npmjs.com/package/node-forge#rsa

    // encrypt data with a public key using RSAES-OAEP/SHA-256/MGF1-SHA-1
// compatible with Java's RSA/ECB/OAEPWithSHA-256AndMGF1Padding
var encrypted = publicKey.encrypt(bytes, 'RSA-OAEP', {
  md: forge.md.sha256.create(),
  mgf1: {
    md: forge.md.sha256.create()
  }
});

Thank you谢谢

Firstly, you shouldn't use "ECB" mode cipher, because:首先,你不应该使用“ECB”模式密码,因为:

  1. ECB is a block cipher mode, RSA isn't an algorithm based on that mode of operation. ECB 是分组密码模式,RSA 不是基于该操作模式的算法。
  2. If you use an algorithm based on that mode of operation (for example AES), you shouldn't use ECB, because it doesn't have IV (Initialization Vector), so it's insecure and a crypto analyzer could break the cipher.如果您使用基于该操作模式的算法(例如 AES),则不应使用 ECB,因为它没有 IV(初始化向量),因此它不安全并且密码分析器可能会破解密码。 You could use CBC, it has IV, or GCM, if you want to share sensitive information to external systems and prevent Oracle Padding.如果您想与外部系统共享敏感信息并防止 Oracle Padding,您可以使用 CBC,它有 IV 或 GCM。 I recommend you visit the following link:我建议您访问以下链接:

MSC61-J. MSC61-J。 Do not use insecure or weak cryptographic algorithms 不要使用不安全或弱加密算法

So, in this case, you just need to use OAEP for RSA encryption, because it's a padding scheme and it helpts to prevent Oracle Padding for asymetric algorithms, then change your code for: RSA/None/OAEPWithSHA-256AndMGF1Padding .因此,在这种情况下,您只需要使用 OAEP 进行 RSA 加密,因为它是一种填充方案,它有助于防止 Oracle Padding 用于非对称算法,然后将您的代码更改为: RSA/None/OAEPWithSHA-256AndMGF1Padding Maybe, you could get compatibility with Node.js.也许,您可以获得与 Node.js 的兼容性。 Also, I recommend you visit the official web site:另外,我建议您访问官方网站:

JCA Reference Guide JCA 参考指南

I hope this information helps you.希望这些信息对您有所帮助。

Good luck.祝你好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java的RSA / ECB / OAEPWITHSHA-256ANDMGF1PADDING在PHP中等效 - Java's RSA/ECB/OAEPWITHSHA-256ANDMGF1PADDING equivalent in PHP Java RSA/ECB/OAEPWITHSHA-256ANDMGF1PADDING 迁移到 Go - Java RSA/ECB/OAEPWITHSHA-256ANDMGF1PADDING Migrate To Go C#等效于Java RSA / ECB / OAEPWithSHA-256AndMGF1Padding - C# equivalent to Java RSA/ECB/OAEPWithSHA-256AndMGF1Padding 获取 ruby 的“RSA/ECB/OAEPWithSHA-256AndMGF1Padding”组合 - Get this “RSA/ECB/OAEPWithSHA-256AndMGF1Padding” combination for ruby java RSA/ECB/OAEPWithSHA 256AndMGF1Padding 在 golang 中等效 - java RSA/ECB/OAEPWithSHA 256AndMGF1Padding equivalent in golang 分解 RSA/ECB/OAEPWithSHA-256AndMGF1Padding - Breaking down RSA/ECB/OAEPWithSHA-256AndMGF1Padding “RSA/ECB/OAEPWITHSHA256ANDMGF1PADDING”和“RSA/ECB/OAEPWITHSHA-256ANDMGF1PADDING”之间的区别是什么 - what is deference between "RSA/ECB/OAEPWITHSHA256ANDMGF1PADDING" and "RSA/ECB/OAEPWITHSHA-256ANDMGF1PADDING" C# Bouncy Castle 中的 RSA/ECB/OAEPWITHSHA-256ANDMGF1PADDING - 对于 RSA 密码输入太大 - RSA/ECB/OAEPWITHSHA-256ANDMGF1PADDING in C# Bouncy Castle - input too large for RSA cipher RSA / ECB / OAEPWithSHA-256AndMGF1Padding但MGF1使用SHA-256? - RSA/ECB/OAEPWithSHA-256AndMGF1Padding but with MGF1 using SHA-256? 错误的填充例外-pkcs11中的RSA / ECB / OAEPWITHSHA-256ANDMGF1PADDING - Bad Padding Exception - RSA/ECB/OAEPWITHSHA-256ANDMGF1PADDING in pkcs11
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM