我目前正在开发一个内核模块,在其中执行RSA签名验证。公钥总是在crypto_akcipher_set_pub_key失败。
我通过python生成公共密钥,这是我的公共密钥: -----开始公钥----- MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqPdPMzEYirodOYw / GoLyFUo547OBHm3O9 / KpF6yoW9lqiDHGUF4Hs5pk / tTElSMh2o5wtM1zuehmJHtetnoV16Sko4Fx6C0VXxUqJyg8twKvC4Cj / nmFK4ARayn5AaJRhvIMq560mfh2UotyIL6Zsi + f9Z8usuDP8MWyhM9nZGQIDAQAB ----- END公钥-----
这是我的代码:
*tfm = crypto_alloc_akcipher("rsa", 0, 0);
...
req = akcipher_request_alloc(*tfm, GFP_KERNEL);
...
err = crypto_akcipher_set_pub_key(*tfm, data, len);
if(err) {
printk("set the public key error\n");
akcipher_request_free(req);
return NULL;
}
我遇到类似的问题:crypto_akcipher_set_pub_key in kernel asymmetric crypto always returns error
我键入命令:hereopenssl asn1parse -in 2
输出:
0:d=0 hl=3 l= 159 cons: SEQUENCE
3:d=1 hl=2 l= 13 cons: SEQUENCE
5:d=2 hl=2 l= 9 prim: OBJECT :rsaEncryption
16:d=2 hl=2 l= 0 prim: NULL
18:d=1 hl=3 l= 141 prim: BIT STRING
然后我输入:openssl asn1parse -in 2 -strparse 18
输出:
0:d=0 hl=3 l= 137 cons: SEQUENCE
3:d=1 hl=3 l= 129 prim: INTEGER :AA3DD3CCCC4622AE874E630FC6A0BC85528E78ECE0479B73BDFCAA45EB2A16F65AA20C71941781ECE6993FB5312548C876A39C2D335CEE7A19891ED7AD9E8575E92928E05C7A0B4557C54A89CA0F2DC0ABC2E028FF9E614AE0045ACA7E40689461BC832AE7AD267E1D94A2DC882FA66C8BE7FD67CBACB833FC316CA133D9D919
135:d=1 hl=2 l= 3 prim: INTEGER :010001
这是我的代码:
const char *public_key="AA3DD3CCCC4622AE874E630FC6A0BC85528E78ECE0479B73BDFCAA45EB2A16F65AA20C71941781ECE6993FB5312548C876A39C2D335CEE7A19891ED7AD9E8575E92928E05C7A0B4557C54A89CA0F2DC0ABC2E028FF9E614AE0045ACA7E40689461BC832AE7AD267E1D94A2DC882FA66C8BE7FD67CBACB833FC316CA133D9D919";
但是,公钥始终在crypto_akcipher_set_pub_key处失败。
谢谢!