- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在学习在我的程序中使用 OpenSSL 库。在代码中,我生成了一个私钥,并立即使用该 key 加密了一条消息。但总是失败。请帮助我。
private_key = RSA_generate_key(RSA_KEY_LENGTH, RSA_3, NULL, NULL);
if (RSA_check_key(private_key) < 1) {
printf("generate_key: key generation failed\n");
exit(-1);
}
unsigned char msg[25];
unsigned char cipher[128];
strcpy((char*)msg, "hello");
int ret = RSA_private_encrypt(25, msg, cipher, private_key,
RSA_PKCS1_OAEP_PADDING);
if (ret < 0) {
printf("encryption in key generation failed\n");
printf ("%s\n", ERR_error_string (ERR_get_error (), (char *) cipher));
exit (-1);
}
这总是失败,这是我使用 ERR_error_string 得到的错误。
error:04066076:lib(4):func(102):reason(118)
最佳答案
查看文档:
人RSA_private_encrypt
RSA_private_encrypt() signs the flen bytes at from (usually a message digest with an algorithm identifier) using the private key rsa and stores the signature in to. to must point to RSA_size(rsa) bytes of memory.
padding denotes one of the following modes:
RSA_PKCS1_PADDING
PKCS #1 v1.5 padding. This function does not handle the algorithmIdentifier specified in PKCS #1. When generating or verifying PKCS #1 signatures, RSA_sign(3) and RSA_verify(3) should be used.
RSA_NO_PADDING
Raw RSA signature. This mode should only be used to implement cryptographically sound padding modes in the application code. Signing user data directly with RSA is insecure.
我不知道你从哪里得到 RSA_PKCS1_OAEP_PADDING,但上面列出了唯一支持的填充。
关于c - RSA_private_encrypt 总是失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11046513/
我正在学习在我的程序中使用 OpenSSL 库。在代码中,我生成了一个私钥,并立即使用该 key 加密了一条消息。但总是失败。请帮助我。 private_key = RSA_generate_key(
在下面的例子中,我们使用RSA 256-bit private key 来加密一个 32 字节的消息而不填充,并将结果存储在同一个内存块中。 #include unsigned char er
我用 RSA 加密了我的字符串,但它现在是一个 unsigned char *。如何创建可以为用户输出的人类可读的 std::string?我想在亚马逊签名的网址中使用它。这是来自 GitHub 的代
我不是数学家(请原谅我在这篇文章中所说的话!),但据我所知RSA加密和解密应该是相同的操作:M ^ e 模 n 其中 M 是我想要解密/加密的内容,e 是指数,n 是模块(在我的例子中是私有(priv
我正在尝试实现 Chef API client在 Go 中,但坚持尝试创建正确的请求 header RSA 签名。根据documentation : A canonical header is sig
我是一名优秀的程序员,十分优秀!