- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试使用 ECDH key 实现 CMS 加密。引用 openssl CMS with ECDH EnvelopedData命令行运行完美,但我的程序出现错误 -
Error Encrypting Data
140508524291744:error:2E06507D:CMS routines:CMS_add1_recipient_cert:not supported for this key type:cms_env.c:210:
在下面的代码中,recip.pem 是使用此处的步骤创建的 openssl CMS with ECDH EnvelopedData
#include <stdio.h>
#include <openssl/pem.h>
#include <openssl/x509.h>
#include <openssl/cms.h>
int main (int argc, char **argv)
{
CMS_ContentInfo *cms1 = NULL;
BIO *in = NULL, *out = NULL, *tbio = NULL;
X509 *rcert = NULL;
int ret = 1;
int flags = CMS_STREAM;
OpenSSL_add_all_algorithms();
ERR_load_crypto_strings();
tbio = BIO_new_file("recip.pem", "r");
if (!tbio)
goto err;
rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
if (!rcert)
goto err;
in = BIO_new_file("encr.txt", "r");
flags |= CMS_PARTIAL;
cms1 = CMS_encrypt(NULL, in, EVP_des_ede3_cbc(), flags);
CMS_RecipientInfo *ri;
ri = CMS_add1_recipient_cert(cms1, rcert, flags);
if (!ri)
goto err;
if(!CMS_final(cms1, in, NULL, flags))
goto err;
if (!cms1)
goto err;
out = BIO_new_file("cms1.pem", "w");
if(!out)
goto err;
if(!PEM_write_bio_CMS_stream(out, cms1, in, flags))
goto err;
ret = 0;
err:
if (ret) {
fprintf(stderr, "Error Encrypting Data\n");
ERR_print_errors_fp(stderr);
}
if (cms1)
CMS_ContentInfo_free(cms1);
if (rcert)
X509_free(rcert);
if (in)
BIO_free(in);
if (out)
BIO_free(out);
if (tbio)
BIO_free(tbio);
return ret;
}
文档指出不支持 ECC key ,但命令行 cms 应用程序能够毫无问题地执行此操作。我逐步浏览了 cms 应用程序,但无法弄清楚我在做什么。还尝试了 demos 文件夹中的 cms_enc.c,但它也不能处理 ecc key 。
我希望我的程序做的是
> openssl cms -encrypt -aes256 -in "x.txt" -out "y.bin" -outformat PEM ecc.crt
> openssl asn1parse -dump -in "y.bin"
0:d=0 hl=4 l= 855 cons: SEQUENCE
4:d=1 hl=2 l= 9 prim: OBJECT :pkcs7-envelopedData
15:d=1 hl=4 l= 840 cons: cont [ 0 ]
19:d=2 hl=4 l= 836 cons: SEQUENCE
23:d=3 hl=2 l= 1 prim: INTEGER :02
26:d=3 hl=4 l= 379 cons: SET
30:d=4 hl=4 l= 375 cons: cont [ 1 ]
34:d=5 hl=2 l= 1 prim: INTEGER :03
37:d=5 hl=3 l= 151 cons: cont [ 0 ]
40:d=6 hl=3 l= 148 cons: cont [ 1 ]
43:d=7 hl=2 l= 9 cons: SEQUENCE
45:d=8 hl=2 l= 7 prim: OBJECT :id-ecPublicKey
54:d=7 hl=3 l= 134 prim: BIT STRING
0000 - 00 04 00 3e 4c 80 5b bb-10 ff 83 30 33 1f 44 ab ...>L.[....03.D.
0010 - ad 2c a2 9d a9 5a 19 5f-8e 5a dc 30 a2 4d f5 19 .,...Z._.Z.0.M..
0020 - 51 49 e6 cb ff 63 08 e7-87 e8 d3 66 60 f5 0f 67 QI...c.....f`..g
0030 - c1 94 3a aa b9 88 3c 7c-5c cd 5a cd 4e f2 5f ba ..:...<|\.Z.N._.
0040 - 15 05 0d bc 01 be 6c 2c-32 fd b1 3d d1 d1 52 f8 ......l,2..=..R.
0050 - e0 43 a5 03 25 05 2a 63-32 47 d9 e6 15 71 75 d0 .C..%.*c2G...qu.
0060 - 5b 45 ca f5 db 91 e2 68-4c 65 29 1c 6d c3 1f f1 [E.....hLe).m...
0070 - 3a e4 55 78 1b dd 95 b5-bd 24 06 31 34 fa 26 c5 :.Ux.....$.14.&.
0080 - 52 8f c9 24 37 4c R..$7L
191:d=5 hl=2 l= 23 cons: SEQUENCE
193:d=6 hl=2 l= 6 prim: OBJECT :1.3.132.1.11.1
201:d=6 hl=2 l= 13 cons: SEQUENCE
203:d=7 hl=2 l= 9 prim: OBJECT :id-aes256-wrap
214:d=7 hl=2 l= 0 prim: NULL
216:d=5 hl=3 l= 190 cons: SEQUENCE
219:d=6 hl=3 l= 187 cons: SEQUENCE
222:d=7 hl=3 l= 142 cons: SEQUENCE
225:d=8 hl=3 l= 128 cons: SEQUENCE
228:d=9 hl=2 l= 11 cons: SET
230:d=10 hl=2 l= 9 cons: SEQUENCE
232:d=11 hl=2 l= 3 prim: OBJECT :countryName
237:d=11 hl=2 l= 2 prim: PRINTABLESTRING :US
241:d=9 hl=2 l= 19 cons: SET
243:d=10 hl=2 l= 17 cons: SEQUENCE
245:d=11 hl=2 l= 3 prim: OBJECT :stateOrProvinceName
250:d=11 hl=2 l= 10 prim: UTF8STRING :California
## other cert params ##
356:d=8 hl=2 l= 9 prim: INTEGER :FEEAB1D7F247D77B
367:d=7 hl=2 l= 40 prim: OCTET STRING
0000 - d5 fd 5c 37 ac 0b b7 ad-07 b7 42 38 5a 3e a5 bc ..\7......B8Z>..
0010 - 5e eb 1f bf a4 b9 63 bb-6d 58 87 a5 3c 96 34 68 ^.....c.mX..<.4h
0020 - 55 26 4e 63 f0 16 92 0a- U&Nc....
409:d=3 hl=4 l= 446 cons: SEQUENCE
413:d=4 hl=2 l= 9 prim: OBJECT :pkcs7-data
424:d=4 hl=2 l= 29 cons: SEQUENCE
426:d=5 hl=2 l= 9 prim: OBJECT :aes-256-cbc
437:d=5 hl=2 l= 16 prim: OCTET STRING
0000 - 82 cd 6e 4b 7a 2a bc 59-63 c0 55 a3 bb b1 9a e6 ..nKz*.Yc.U.....
455:d=4 hl=4 l= 400 prim: cont [ 0 ]
最佳答案
The command line works flawlessly but my program is giving an error
您是否构建了 openssl
二进制文件的本地副本,正如您所引用的链接所假设的那样?如果是这样,那么不同的行为很可能是由不同版本的 openssl 引起的(假设您将示例代码链接到系统库)。最近添加了对 EC 的支持;我的系统 OpenSSL 版本 1.0.1f 报告了与您显示的相同的错误,而本地安装的版本 1.0.2a 使用 EC key 成功加密。
因此,如果您需要您的二进制文件使用 EC key ,请在您的系统上安装更新的 OpenSSL,或者将二进制文件静态链接到本地构建的 OpenSSL 库(libssl 和 libcrypto)。
关于CMS_encrypt 使用 ECDH key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29721721/
因此,我尝试使用椭圆曲线 DH 的 OpenSSL EVP 方法执行 key 交换,以派生共享 key 。这对于在 GCM 模式下使用 AES 为自定义协议(protocol)提供强大的安全性是必要的
在我的场景中,Alice 和 Bob 已就使用哪条曲线达成一致。 Alice 生成公钥和私钥 Alice 将公钥发送给 Bob Bob 生成他的 key ,并根据他收到的 Alice 公钥生成 ses
我在 Windows 7 系统上使用 Oracle Java 8 (8u112) 和“适用于 JDK/JRE 8 的 Java 加密扩展 (JCE) 无限强度管辖策略文件”。为了提高我对安全套接字的理
我正在寻找示例 Java 代码来实现 ECDH 加密的密码。我已经找到了获取所需 key 的方法,但仍未找到加密文本的解决方案。如果有人可以提供一些指导,我们将不胜感激。 顺便说一下,我在为 Andr
我对 OpenSSL 库中的 ECDH 有疑问。 在文件'ecdhtest.c'的第159行,我们可以确认私钥的值如下: BN_print(out, a->priv_key); 但是,当我使用 Mak
我知道 ECDH 中的 key 大小取决于椭圆曲线的大小。 如果是256位曲线(secp256k1), key 将为: Public: 32 bytes * 2 + 1 = 65 (uncompres
我正在构建一个实现 ECDSA_METHOD 的 OpenSSL 引擎,其中包括签名创建和签名验证功能。由于 ECDHE 私钥的唯一用途是与签名创建相关,因此不需要从引擎导出 key 并将其呈现在其他
Java Cryptography ArchitectureStandard Algorithm Name Documentation Java 6 的页面列出了 ECDHE 密码套件。因此,我希望它
我正在尝试了解 HTTPS 的工作原理并进行一些实际测试。 我有一个通过 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA 加密的 HTTPS 通信捕获的数据。 如果我没理解错的话
我正在尝试使用 ECDH key 实现 CMS 加密。引用 openssl CMS with ECDH EnvelopedData命令行运行完美,但我的程序出现错误 - Error Encryptin
我读过这篇文章document通过ECDH-CURVE25519算法生成 key 对。但是当我在 window.crypto.subtle.generateKey 中指定 ECDH-CURVE2551
我正在将一个方法从 nodeSJ 转换为 Java,但我无法使其正常工作。我一直在尝试计算派生共享 secret 。 希望有人能发现我在将 NodeJS 移植到 Java 时做错了什么。 NodeJS
前言:我不知道这个问题在这里问更合适还是在 Crypto 网站上问更合适。请随意移动或删除或任何适当的 SE 操作。 有人要求我帮助更新一些加密软件。一般来说,该软件已经执行了以下步骤,其中没有一个是
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
我目前正在研究 ECDH key 交换实现。我为此使用 P-384 曲线。其他曲线也是可能的,但我认为实现应该非常相似。 客户端(Javascript)和服务器(Java)想要找到一个共享的 secr
我正在开发一个 iOS 应用程序,我想实现 ECDH 以确保安全。我使用这个应用程序(https://github.com/DigitalLeaves/AsymmetricCrypto)生成一对 ke
我正在尝试使用本地证书颁发机构,但我不断收到“ECDH 服务器 key 交换消息上的无效签名”错误。提前为这个问题的复杂性道歉。您可以通过以下方式从 github 获取完整的源代码: git clon
根据 RFC客户端发送使用服务器的 RSA 公钥加密的预主 key 。但是当他们使用 ECDHE 作为非对称算法时,客户端 key 交换消息将包含客户端的公钥。如果是这样的话?客户端何时发送预主 ke
我正在构建一个 Web API,我需要实现 ECDH 来执行端到端加密。在服务器端我有一个 C# 应用程序,在客户端我有一个 Javascript 应用程序。 我能够交换 key 、生成私钥并加密消息
我对 ECDH(椭圆曲线 Diffie-Hellman)加密有一个小问题。我使用 BouncyCaSTLe 库。 这是我生成 key 的函数: public static KeyPair genera
我是一名优秀的程序员,十分优秀!