gpt4 book ai didi

java - 来自Bouncy CaSTLe的ECIES对应的ECC解密

转载 作者:数据小太阳 更新时间:2023-10-29 07:55:56 28 4
gpt4 key购买 nike

我正在尝试解密在 Java 中使用 ECIES 加密的 Ruby 文件

  • BouncyCaSTLe 作为 JCE 提供者
  • ECIES 算法
  • P-384命名曲线

在 Java 中,加密是使用 Cipher.doFinal() 完成的,然后写入文件。一个测试用例实现加解密。

在 Ruby 中,我只能找到 OpenSSL::PKey::EC 实现,但这似乎没有加密或解密,只有验证和签名。

有谁知道在 Ruby 中执行此操作的方法吗?我最坏的情况是简单地从 Ruby 调用 Java 解密路由,但这真的不是我想要的方式。

最佳答案

ECC decryption corresponding to ECIES from Bouncy Castle

ECIES 是 Shoup 的集成加密系统。它不仅仅是简单的 EC 加密和解密。您可以在 A Proposal for an ISO Standard for Public Key Encryption 找到 Shoup 的论文.


In Ruby all i can find is the OpenSSL::PKey::EC implementation

OpenSSL 没有有 ECIES 实现。它也没有实现 Abdalla、Bellare 和 Rogaway 的 DHAES。


My worst case scenario would be to simply call the Java decryption routing from Ruby, but that really isn't the way i want to go.

您可能不得不转向 Java。


相关(抱歉误入 C++):Crypto++还有ECIES。但是,Bouncy CaSTLe 和 Crypto++ 实现开箱即用。参见 Problem with the way gfpcrypt HMAC's the encoding parameters' length in DHAES_MODE在 Crypto++ 邮件列表上。

互操作性问题是在使用 DHAES_MODE 时作为安全参数散列的标签大小的差异。 Crypto++ 使用 8 字节标签,而 Bouncy CaSTLe 使用 4 字节标签。我不记得谁是/是正确的。

Elliptic Curve Integrated Encryption Scheme 上的 Crypto++ 页面底部,根据 Jessie Wilson 在 cryptopp-ecies-bc.zip 中的评论提供了一个补丁。下载、应用并使用 ECIES_BC 类而不是 ECIES 类。

这是补丁的本质。 BC_COMPAT 是模板参数。

diff --git a/gfpcrypt.h b/gfpcrypt.h
index 7af993f..18ea104 100644
--- a/gfpcrypt.h
+++ b/gfpcrypt.h
@@ -408,7 +408,9 @@ CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_GFP<DL_GroupParameters_DSA>;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_WithSignaturePairwiseConsistencyTest<DL_PrivateKey_GFP<DL_GroupParameters_DSA>, DSA2<SHA> >;

//! the XOR encryption method, for use with DL-based cryptosystems
-template <class MAC, bool DHAES_MODE>
+// Set BC_COMPAT=true if interop'ing with Bouncy Castle. Thanks to Jesse Wilson and Daniele Perito.
+// See https://groups.google.com/d/msg/cryptopp-users/vR8GSL8wxPA/Bf9koUDyZ88J.
+template <class MAC, bool DHAES_MODE, bool BC_COMPAT = false>
class DL_EncryptionAlgorithm_Xor : public DL_SymmetricEncryptionAlgorithm
{
public:
@@ -442,9 +444,17 @@ public:
mac.Update(encodingParameters.begin(), encodingParameters.size());
if (DHAES_MODE)
{
- byte L[8] = {0,0,0,0};
- PutWord(false, BIG_ENDIAN_ORDER, L+4, word32(encodingParameters.size()));
- mac.Update(L, 8);
+ if (BC_COMPAT) {
+ byte L[4];
+ PutWord(false, BIG_ENDIAN_ORDER, L, word32(8 * encodingParameters.size()));
+ mac.Update(L, 4);
+ }
+ else
+ {
+ byte L[8] = {0,0,0,0};
+ PutWord(false, BIG_ENDIAN_ORDER, L+4, word32(encodingParameters.size()));
+ mac.Update(L, 8);
+ }
}
mac.Final(ciphertext + plaintextLength);
}
@@ -471,9 +481,17 @@ public:
mac.Update(encodingParameters.begin(), encodingParameters.size());
if (DHAES_MODE)
{
- byte L[8] = {0,0,0,0};
- PutWord(false, BIG_ENDIAN_ORDER, L+4, word32(encodingParameters.size()));
- mac.Update(L, 8);
+ if (BC_COMPAT) {
+ byte L[4];
+ PutWord(false, BIG_ENDIAN_ORDER, L, word32(8 * encodingParameters.size()));
+ mac.Update(L, 4);
+ }
+ else
+ {
+ byte L[8] = {0,0,0,0};
+ PutWord(false, BIG_ENDIAN_ORDER, L+4, word32(encodingParameters.size()));
+ mac.Update(L, 8);
+ }
}
if (!mac.Verify(ciphertext + plaintextLength))
return DecodingResult();

关于java - 来自Bouncy CaSTLe的ECIES对应的ECC解密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24269743/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com