一次发现RSA der格式公钥2048位(256bytes)有的长度292有的长度294于是分析了下:
[root@8f64ba75cbd1 tmp]# ll anewpub.der 1_pub.der
-rw------- 1 root root 294 Apr 8 02:48 1_pub.der
-rw------- 1 root root 292 Apr 8 02:25 anewpub.der
[root@8f64ba75cbd1 tmp]#
[root@8f64ba75cbd1 tmp]# hexdump -C anewpub.der
00000000 30 82 01 20 30 0d 06 09 2a 86 48 86 f7 0d 01 01 |0.. 0...*.H.....|
00000010 01 05 00 03 82 01 0d 00 30 82 01 08 02 82 01 01 |........0.......|
00000020 00 e4 94 de 63 55 28 cc e5 4f 41 28 ee b4 db 67 |....cU(..OA(...g|
00000030 6a 5a fb 1f 92 7a 07 b6 ff 5b 27 b1 00 2d 85 f3 |jZ...z...['..-..|
00000040 84 6e ed 32 d2 f9 55 36 52 9d 84 bb a8 6d 42 ed |.n.2..U6R....mB.|
00000050 51 e4 34 99 83 62 b6 ed 86 27 bd 9b e7 91 b5 fb |Q.4..b...'......|
00000060 8c b5 18 12 c9 e6 53 5f 69 b7 71 8b ea fb 88 f6 |......S_i.q.....|
00000070 5b ed fc 9c aa 2e 33 12 1c 7d 2b 6d f8 65 9c b2 |[.....3..}+m.e..|
00000080 62 21 a0 6f 21 d3 fa 9a 44 8b 6f 8d c4 08 2d 4a |b!.o!...D.o...-J|
00000090 43 17 24 e4 c5 3f 53 cc 3a 4f 98 24 35 8b fa 36 |C.$..?S.:O.$5..6|
000000a0 54 71 5f 40 52 eb b8 e6 77 d5 bb 0b 2e db ae 99 |Tq_@R...w.......|
000000b0 b3 52 5f 4b 45 6b 79 3b 50 79 25 1e b7 e4 30 b4 |.R_KEky;Py%...0.|
000000c0 b1 a9 b2 dc 0d 41 05 e7 41 65 2a f8 fd 40 4b 34 |.....A..Ae*..@K4|
000000d0 32 d4 f3 95 38 99 72 29 f0 44 41 a5 06 d7 9b 94 |2...8.r).DA.....|
000000e0 a8 cd a2 e6 d4 e9 06 2a c6 67 71 57 9c 73 b0 86 |.......*.gqW.s..|
000000f0 4e 06 71 ce 31 2d 90 27 69 47 95 46 58 c0 11 eb |N.q.1-.'iG.FX...|
00000100 0e cf 77 13 8e e2 c8 32 e1 8f c4 a1 18 6e 13 22 |..w....2.....n."|
00000110 2a 18 b4 de 93 4e 13 98 df 69 2f 46 74 69 74 ba |*....N...i/Ftit.|
00000120 d3 02 01 03 |....|
00000124
[root@8f64ba75cbd1 tmp]#
[root@8f64ba75cbd1 tmp]# hexdump -C 1_pub.der
00000000 30 82 01 22 30 0d 06 09 2a 86 48 86 f7 0d 01 01 |0.."0...*.H.....|
00000010 01 05 00 03 82 01 0f 00 30 82 01 0a 02 82 01 01 |........0.......|
00000020 00 9b 2c ad a0 45 68 f4 cf bc 76 be 15 aa 92 f9 |..,..Eh...v.....|
00000030 1b 52 92 68 a1 78 a0 ba 3c 36 d2 14 fc fe 7c a0 |.R.h.x..<6....|.|
00000040 4e 24 d8 2d 69 a6 b3 9c 60 b6 92 ba 12 0a 45 6d |N$.-i...`.....Em|
00000050 8f e4 52 7a 9d d3 67 cf bd d5 aa 65 b5 0d 79 bf |..Rz..g....e..y.|
00000060 d8 77 e8 b7 04 0d c5 c6 33 50 6a e2 f6 91 dc 3e |.w......3Pj....>|
00000070 01 fb db f8 e7 62 20 78 9c 96 ea 39 da 75 87 97 |.....b x...9.u..|
00000080 3a 38 b3 73 50 57 ab 98 1f 2e 66 f3 c3 7a ee e7 |:8.sPW....f..z..|
00000090 28 36 b3 7b 69 66 fb fc c0 7e 92 fb 4f 08 5d c4 |(6.{if...~..O.].|
000000a0 39 76 3b e5 0b e2 38 86 a8 e5 d2 c7 38 c8 8a 86 |9v;...8.....8...|
000000b0 49 68 dd 2a 0e d9 27 ee e3 78 d1 f9 e0 1f 18 88 |Ih.*..'..x......|
000000c0 23 09 4c ec 59 e6 e0 d7 ef b7 3d 98 aa f1 41 ed |#.L.Y.....=...A.|
000000d0 eb 28 68 38 2e 91 82 de ac 20 f5 7c f1 37 a6 4f |.(h8..... .|.7.O|
000000e0 05 dd 8b 51 cf f1 83 80 41 cc 35 3a dc a9 ae 57 |...Q....A.5:...W|
000000f0 2b cf b6 ba 45 e5 e3 9a 26 82 aa cb 30 5f 87 1b |+...E...&...0_..|
00000100 29 2e e4 a5 ef 8e 6b 1e c7 13 60 33 af 95 71 57 |).....k...`3..qW|
00000110 bf 20 07 b3 81 b7 aa 15 10 a1 81 f4 d3 4e 38 ee |. ...........N8.|
00000120 bb 02 03 01 00 01 |......|
00000126
[root@8f64ba75cbd1 tmp]#
[root@8f64ba75cbd1 tmp]# openssl rsa -in anewpub.der -pubin -text -noout
Public-Key: (2048 bit)
Modulus:
00:e4:94:de:63:55:28:cc:e5:4f:41:28:ee:b4:db:
67:6a:5a:fb:1f:92:7a:07:b6:ff:5b:27:b1:00:2d:
85:f3:84:6e:ed:32:d2:f9:55:36:52:9d:84:bb:a8:
6d:42:ed:51:e4:34:99:83:62:b6:ed:86:27:bd:9b:
e7:91:b5:fb:8c:b5:18:12:c9:e6:53:5f:69:b7:71:
8b:ea:fb:88:f6:5b:ed:fc:9c:aa:2e:33:12:1c:7d:
2b:6d:f8:65:9c:b2:62:21:a0:6f:21:d3:fa:9a:44:
8b:6f:8d:c4:08:2d:4a:43:17:24:e4:c5:3f:53:cc:
3a:4f:98:24:35:8b:fa:36:54:71:5f:40:52:eb:b8:
e6:77:d5:bb:0b:2e:db:ae:99:b3:52:5f:4b:45:6b:
79:3b:50:79:25:1e:b7:e4:30:b4:b1:a9:b2:dc:0d:
41:05:e7:41:65:2a:f8:fd:40:4b:34:32:d4:f3:95:
38:99:72:29:f0:44:41:a5:06:d7:9b:94:a8:cd:a2:
e6:d4:e9:06:2a:c6:67:71:57:9c:73:b0:86:4e:06:
71:ce:31:2d:90:27:69:47:95:46:58:c0:11:eb:0e:
cf:77:13:8e:e2:c8:32:e1:8f:c4:a1:18:6e:13:22:
2a:18:b4:de:93:4e:13:98:df:69:2f:46:74:69:74:
ba:d3
Exponent: 3 (0x3)
[root@8f64ba75cbd1 tmp]#
[root@8f64ba75cbd1 tmp]#
[root@8f64ba75cbd1 tmp]#
[root@8f64ba75cbd1 tmp]# openssl rsa -in 1_pub.der -pubin -text -noout
Public-Key: (2048 bit)
Modulus:
00:9b:2c:ad:a0:45:68:f4:cf:bc:76:be:15:aa:92:
f9:1b:52:92:68:a1:78:a0:ba:3c:36:d2:14:fc:fe:
7c:a0:4e:24:d8:2d:69:a6:b3:9c:60:b6:92:ba:12:
0a:45:6d:8f:e4:52:7a:9d:d3:67:cf:bd:d5:aa:65:
b5:0d:79:bf:d8:77:e8:b7:04:0d:c5:c6:33:50:6a:
e2:f6:91:dc:3e:01:fb:db:f8:e7:62:20:78:9c:96:
ea:39:da:75:87:97:3a:38:b3:73:50:57:ab:98:1f:
2e:66:f3:c3:7a:ee:e7:28:36:b3:7b:69:66:fb:fc:
c0:7e:92:fb:4f:08:5d:c4:39:76:3b:e5:0b:e2:38:
86:a8:e5:d2:c7:38:c8:8a:86:49:68:dd:2a:0e:d9:
27:ee:e3:78:d1:f9:e0:1f:18:88:23:09:4c:ec:59:
e6:e0:d7:ef:b7:3d:98:aa:f1:41:ed:eb:28:68:38:
2e:91:82:de:ac:20:f5:7c:f1:37:a6:4f:05:dd:8b:
51:cf:f1:83:80:41:cc:35:3a:dc:a9:ae:57:2b:cf:
b6:ba:45:e5:e3:9a:26:82:aa:cb:30:5f:87:1b:29:
2e:e4:a5:ef:8e:6b:1e:c7:13:60:33:af:95:71:57:
bf:20:07:b3:81:b7:aa:15:10:a1:81:f4:d3:4e:38:
ee:bb
Exponent: 65537 (0x10001)
[root@8f64ba75cbd1 tmp]#
其实就是e值的区别:
用代码转换pem公钥为der格式,得到长度只有268,分析发现是只包含了n、e值的结果,没有前面的算法oid信息。
unsigned char *outil_pem_to_der_pub(std::string in, int *len)
{
int ret = 0;
EVP_PKEY *key = NULL;
unsigned char *out = NULL;
do
{
CHECK(in.size() == 0)
CALL_FUNC(key, outil_decode_EVPKEY_pub_from_pem(in), key == NULL)
ret = i2d_PublicKey(key, &out);
if (ret != 0)
{ // success
*len = ret;
break;
}
out = outil_pem_to_der_rsapub(in, len);
if (out != NULL)
{ // success
break;
}
CALL_FUNC(out, outil_pem_to_der_ecpub(in, len), out == NULL)
} while (0);
FREE_NOTNULL(key, EVP_PKEY_free)
return out;
}
可能是第一步i2d_PublicKey就转换成功退出了,这个接口可能不会考虑oid等信息,只干n和e的值。
验证:
失败,因为参数in传入的是PKCS#8格式的公钥(后来才知道的)。
查阅资料,发现是有不同标准的公钥格式PKCS#1和PKCS#8(没有标明RSA):
[root@8f64ba75cbd1 openssl-1.1.1w]# cat anewpub.pem
-----BEGIN PUBLIC KEY-----
MIIBIDANBgkqhkiG9w0BAQEFAAOCAQ0AMIIBCAKCAQEA2bxTTb31GPS58GUpGJ0h
WhZv6j/ujx9dfNWYuhp4fvbXTsEme/TUBQzS/zQbj2lutZq2pihiPDPYyDaXxDDM
Rfi8PJqziG2QmPX3orSJrqy2AHceVzCw6PX+Pe1KKeSP01Rm4VZNMIqJ8kHw+HnQ
IRiFWEGSRsLbKvG1dzEQK7GReSEVsZC7aEqdJVoIlZGxgLzVTLlTqM9p989TvIBT
fFgQATJx1z42Va/icMEsgN7aYlYvOR+EBhMI2MCQ1N2iJubsPujs/khd1IcoalAk
8fOs+eMt1Hq/sGXbfas3hHwM5qIiicV1mDTF0Kn6H5t2OiXG3zpO31Gv6uysigK4
fQIBAw==
-----END PUBLIC KEY-----
[root@8f64ba75cbd1 openssl-1.1.1w]#
[root@8f64ba75cbd1 openssl-1.1.1w]#
[root@8f64ba75cbd1 openssl-1.1.1w]# openssl rsa -pubin -in anewpub.der -RSAPublicKey_out -out anewpubPKCS1.pem
writing RSA key
[root@8f64ba75cbd1 openssl-1.1.1w]#
[root@8f64ba75cbd1 openssl-1.1.1w]# cat anewpubPKCS1.pem
-----BEGIN RSA PUBLIC KEY-----
MIIBCAKCAQEA2bxTTb31GPS58GUpGJ0hWhZv6j/ujx9dfNWYuhp4fvbXTsEme/TU
BQzS/zQbj2lutZq2pihiPDPYyDaXxDDMRfi8PJqziG2QmPX3orSJrqy2AHceVzCw
6PX+Pe1KKeSP01Rm4VZNMIqJ8kHw+HnQIRiFWEGSRsLbKvG1dzEQK7GReSEVsZC7
aEqdJVoIlZGxgLzVTLlTqM9p989TvIBTfFgQATJx1z42Va/icMEsgN7aYlYvOR+E
BhMI2MCQ1N2iJubsPujs/khd1IcoalAk8fOs+eMt1Hq/sGXbfas3hHwM5qIiicV1
mDTF0Kn6H5t2OiXG3zpO31Gv6uysigK4fQIBAw==
-----END RSA PUBLIC KEY-----
[root@8f64ba75cbd1 openssl-1.1.1w]#
[root@8f64ba75cbd1 openssl-1.1.1w]#
[root@8f64ba75cbd1 openssl-1.1.1w]# openssl rsa -pubin -in anewpubPKCS1.pem -outform DER -out anewpubPKCS1.der
writing RSA key
[root@8f64ba75cbd1 openssl-1.1.1w]# ll anewpubPKCS1.der
-rw------- 1 root root 292 Apr 8 06:15 anewpubPKCS1.der
[root@8f64ba75cbd1 openssl-1.1.1w]# openssl rsa -pubin -in anewpubPKCS1.pem -RSAPublicKey_out -outform DER -out anewpubPKCS1.der
writing RSA key
[root@8f64ba75cbd1 openssl-1.1.1w]# ll anewpubPKCS1.der
-rw------- 1 root root 268 Apr 8 06:15 anewpubPKCS1.der
[root@8f64ba75cbd1 openssl-1.1.1w]#
[root@8f64ba75cbd1 openssl-1.1.1w]#
看看有没有代码接口可以调用:
测试出来了:
EVP_PKEY *GenerateRSAKey(unsigned int bits)
{
size_t pri_len = 0; // 私钥长度
size_t pub_len = 0; // 公钥长度
unsigned char *pri_key = NULL; // 私钥
unsigned char *pub_key = NULL; // 公钥
RSA *rsa = NULL;
BIO *pri = NULL;
BIO *pub = NULL;
int ret = 0;
EVP_PKEY *evpk = NULL;
do
{
// 生成密钥对
CALL_FUNC(rsa, RSA_generate_key(bits, RSA_3, NULL, NULL), rsa == NULL)
CALL_FUNC(evpk, EVP_PKEY_new(), evpk == NULL)
CALL_FUNC(ret, EVP_PKEY_set1_RSA(evpk, rsa), ret == 0)
#if 1
pri = BIO_new(BIO_s_mem());
CHECK(pri == NULL)
// 生成私钥
ret = PEM_write_bio_RSAPrivateKey(pri, rsa, NULL, NULL, 0, NULL, NULL);
CHECK(ret <= 0)
// 注意------生成第1种格式的公钥
pub = BIO_new(BIO_s_mem());
CHECK(pub == NULL)
ret = PEM_write_bio_RSAPublicKey(pub, rsa);
CHECK(ret <= 0)
pub_len = BIO_pending(pub);
pub_key = (unsigned char *)malloc(pub_len + 1);
CHECK(pub_key == NULL)
ret = BIO_read(pub, pub_key, pub_len);
CHECK(ret <= 0)
pub_key[pub_len] = 0;
printf("type1:\n%s\n",(char*)pub_key);
// 注意------生成第2种格式的公钥(此处代码中使用这种)
BIO_free(pub);
pub = BIO_new(BIO_s_mem());
CHECK(pub == NULL)
ret = PEM_write_bio_RSA_PUBKEY(pub, rsa);
CHECK(ret <= 0)
pub_len = BIO_pending(pub);
free(pub_key);
pub_key = (unsigned char *)malloc(pub_len + 1);
CHECK(pub_key == NULL)
ret = BIO_read(pub, pub_key, pub_len);
CHECK(ret <= 0)
pub_key[pub_len] = 0;
printf("type2:\n%s\n",(char*)pub_key);
//type 3 PKCS1
free(pub_key);
pub_key = NULL;
pub_len = i2d_RSA_PUBKEY(rsa,&pub_key);
print_hex("rsa pub type 3",pub_key,pub_len);
//type 4 PKCS8
free(pub_key);
pub_key = NULL;
pub_len = i2d_PublicKey(evpk,&pub_key);
print_hex("rsa pub type 4",pub_key,pub_len);
//type 5 PKCS1
free(pub_key);
pub_key = NULL;
pub_len = i2d_PUBKEY(evpk,&pub_key);
print_hex("rsa pub type 5",pub_key,pub_len);
//type 6 PKCS8
free(pub_key);
pub_key = NULL;
pub_len = i2d_RSAPublicKey(rsa,&pub_key);
print_hex("rsa pub type 6",pub_key,pub_len);
// 获取长度
pri_len = BIO_pending(pri);
// 密钥对读取到字符串
pri_key = (unsigned char *)malloc(pri_len + 1);
CHECK(pri_key == NULL)
ret = BIO_read(pri, pri_key, pri_len);
CHECK(ret <= 0)
#endif
} while (0);
// 释放内存
FREE_NOTNULL(rsa, RSA_free)
FREE_NOTNULL(pub, BIO_free)
FREE_NOTNULL(pri, BIO_free)
FREE_NOTNULL(pri_key, free)
FREE_NOTNULL(pub_key, free)
return evpk;
}
[root@8f64ba75cbd1 openssl-1.1.1w]# ./main
type1:
-----BEGIN RSA PUBLIC KEY-----
MIIBCAKCAQEAuXjWEMiuRgd2K8gLtr0ntUzJpvQdrKa2yflUSwM1I6jYgS8BnlcP
UJhVqp2ex7E3LSUg0A6t1jyH6EoS6CQ2qYUIz4STw77UH/8NJcpxoFg9fFTueoiv
MQl4OG45gehugCGYC8RF/Ug4ukQ4TULJARcLI7ynKOq95PGSelqmBe6qoZtfRFdL
P2+43ytsl8bnos6PQwbnmlVgShyFmbO42zPWNHnO153qi1GoxsbkVOgqQ/L2/xNB
8BQZp7Z+R2yzKEUjo5qmVo5BqWUPAh3+H4akoebPCJI0D3LqgZfOjRDLHhFYoL0a
m5khM2IwEDBrURvLtcHm4WO2vjP+OKa/6QIBAw==
-----END RSA PUBLIC KEY-----
type2:
-----BEGIN PUBLIC KEY-----
MIIBIDANBgkqhkiG9w0BAQEFAAOCAQ0AMIIBCAKCAQEAuXjWEMiuRgd2K8gLtr0n
tUzJpvQdrKa2yflUSwM1I6jYgS8BnlcPUJhVqp2ex7E3LSUg0A6t1jyH6EoS6CQ2
qYUIz4STw77UH/8NJcpxoFg9fFTueoivMQl4OG45gehugCGYC8RF/Ug4ukQ4TULJ
ARcLI7ynKOq95PGSelqmBe6qoZtfRFdLP2+43ytsl8bnos6PQwbnmlVgShyFmbO4
2zPWNHnO153qi1GoxsbkVOgqQ/L2/xNB8BQZp7Z+R2yzKEUjo5qmVo5BqWUPAh3+
H4akoebPCJI0D3LqgZfOjRDLHhFYoL0am5khM2IwEDBrURvLtcHm4WO2vjP+OKa/
6QIBAw==
-----END PUBLIC KEY-----
rsa pub type 3[len:292 | 0x124]
30 82 01 20 30 0d 06 09 2a 86 48 86 f7 0d 01 01 01 05 00 03 82 01 0d 00 30 82 01 08 02 82 01 01 00 b9 78 d6 10 c8 ae 46 07 76 2b c8 0b b6 bd 27 b5 4c c9 a6 f4 1d ac a6 b6 c9 f9 54 4b 03 3
5 23 a8 d8 81 2f 01 9e 57 0f 50 98 55 aa 9d 9e c7 b1 37 2d 25 20 d0 0e ad d6 3c 87 e8 4a 12 e8 24 36 a9 85 08 cf 84 93 c3 be d4 1f ff 0d 25 ca 71 a0 58 3d 7c 54 ee 7a 88 af 31 09 78 38 6e
39 81 e8 6e 80 21 98 0b c4 45 fd 48 38 ba 44 38 4d 42 c9 01 17 0b 23 bc a7 28 ea bd e4 f1 92 7a 5a a6 05 ee aa a1 9b 5f 44 57 4b 3f 6f b8 df 2b 6c 97 c6 e7 a2 ce 8f 43 06 e7 9a 55 60 4a
1c 85 99 b3 b8 db 33 d6 34 79 ce d7 9d ea 8b 51 a8 c6 c6 e4 54 e8 2a 43 f2 f6 ff 13 41 f0 14 19 a7 b6 7e 47 6c b3 28 45 23 a3 9a a6 56 8e 41 a9 65 0f 02 1d fe 1f 86 a4 a1 e6 cf 08 92 34 0
f 72 ea 81 97 ce 8d 10 cb 1e 11 58 a0 bd 1a 9b 99 21 33 62 30 10 30 6b 51 1b cb b5 c1 e6 e1 63 b6 be 33 fe 38 a6 bf e9 02 01 03
rsa pub type 4[len:268 | 0x10c]
30 82 01 08 02 82 01 01 00 b9 78 d6 10 c8 ae 46 07 76 2b c8 0b b6 bd 27 b5 4c c9 a6 f4 1d ac a6 b6 c9 f9 54 4b 03 35 23 a8 d8 81 2f 01 9e 57 0f 50 98 55 aa 9d 9e c7 b1 37 2d 25 20 d0 0e a
d d6 3c 87 e8 4a 12 e8 24 36 a9 85 08 cf 84 93 c3 be d4 1f ff 0d 25 ca 71 a0 58 3d 7c 54 ee 7a 88 af 31 09 78 38 6e 39 81 e8 6e 80 21 98 0b c4 45 fd 48 38 ba 44 38 4d 42 c9 01 17 0b 23 bc
a7 28 ea bd e4 f1 92 7a 5a a6 05 ee aa a1 9b 5f 44 57 4b 3f 6f b8 df 2b 6c 97 c6 e7 a2 ce 8f 43 06 e7 9a 55 60 4a 1c 85 99 b3 b8 db 33 d6 34 79 ce d7 9d ea 8b 51 a8 c6 c6 e4 54 e8 2a 43
f2 f6 ff 13 41 f0 14 19 a7 b6 7e 47 6c b3 28 45 23 a3 9a a6 56 8e 41 a9 65 0f 02 1d fe 1f 86 a4 a1 e6 cf 08 92 34 0f 72 ea 81 97 ce 8d 10 cb 1e 11 58 a0 bd 1a 9b 99 21 33 62 30 10 30 6b 5
1 1b cb b5 c1 e6 e1 63 b6 be 33 fe 38 a6 bf e9 02 01 03
rsa pub type 5[len:292 | 0x124]
30 82 01 20 30 0d 06 09 2a 86 48 86 f7 0d 01 01 01 05 00 03 82 01 0d 00 30 82 01 08 02 82 01 01 00 b9 78 d6 10 c8 ae 46 07 76 2b c8 0b b6 bd 27 b5 4c c9 a6 f4 1d ac a6 b6 c9 f9 54 4b 03 3
5 23 a8 d8 81 2f 01 9e 57 0f 50 98 55 aa 9d 9e c7 b1 37 2d 25 20 d0 0e ad d6 3c 87 e8 4a 12 e8 24 36 a9 85 08 cf 84 93 c3 be d4 1f ff 0d 25 ca 71 a0 58 3d 7c 54 ee 7a 88 af 31 09 78 38 6e
39 81 e8 6e 80 21 98 0b c4 45 fd 48 38 ba 44 38 4d 42 c9 01 17 0b 23 bc a7 28 ea bd e4 f1 92 7a 5a a6 05 ee aa a1 9b 5f 44 57 4b 3f 6f b8 df 2b 6c 97 c6 e7 a2 ce 8f 43 06 e7 9a 55 60 4a
1c 85 99 b3 b8 db 33 d6 34 79 ce d7 9d ea 8b 51 a8 c6 c6 e4 54 e8 2a 43 f2 f6 ff 13 41 f0 14 19 a7 b6 7e 47 6c b3 28 45 23 a3 9a a6 56 8e 41 a9 65 0f 02 1d fe 1f 86 a4 a1 e6 cf 08 92 34 0
f 72 ea 81 97 ce 8d 10 cb 1e 11 58 a0 bd 1a 9b 99 21 33 62 30 10 30 6b 51 1b cb b5 c1 e6 e1 63 b6 be 33 fe 38 a6 bf e9 02 01 03
rsa pub type 6[len:268 | 0x10c]
30 82 01 08 02 82 01 01 00 b9 78 d6 10 c8 ae 46 07 76 2b c8 0b b6 bd 27 b5 4c c9 a6 f4 1d ac a6 b6 c9 f9 54 4b 03 35 23 a8 d8 81 2f 01 9e 57 0f 50 98 55 aa 9d 9e c7 b1 37 2d 25 20 d0 0e a
d d6 3c 87 e8 4a 12 e8 24 36 a9 85 08 cf 84 93 c3 be d4 1f ff 0d 25 ca 71 a0 58 3d 7c 54 ee 7a 88 af 31 09 78 38 6e 39 81 e8 6e 80 21 98 0b c4 45 fd 48 38 ba 44 38 4d 42 c9 01 17 0b 23 bc
a7 28 ea bd e4 f1 92 7a 5a a6 05 ee aa a1 9b 5f 44 57 4b 3f 6f b8 df 2b 6c 97 c6 e7 a2 ce 8f 43 06 e7 9a 55 60 4a 1c 85 99 b3 b8 db 33 d6 34 79 ce d7 9d ea 8b 51 a8 c6 c6 e4 54 e8 2a 43
f2 f6 ff 13 41 f0 14 19 a7 b6 7e 47 6c b3 28 45 23 a3 9a a6 56 8e 41 a9 65 0f 02 1d fe 1f 86 a4 a1 e6 cf 08 92 34 0f 72 ea 81 97 ce 8d 10 cb 1e 11 58 a0 bd 1a 9b 99 21 33 62 30 10 30 6b 5
1 1b cb b5 c1 e6 e1 63 b6 be 33 fe 38 a6 bf e9 02 01 03
type 1和type2是pem数据。
type 3 和 type 5 可以。
也就是
i2d_PUBKEY(evpk,&pub_key);和i2d_RSA_PUBKEY(rsa,&pub_key);结果是PKCS1格式的。
i2d_PublicKey(evpk,&pub_key);和i2d_RSAPublicKey(rsa,&pub_key);结果是PKCS8格式的。
而pem格式则是
PEM_write_bio_RSAPublicKey(pub, rsa);结果是PKCS1的
PEM_write_bio_RSA_PUBKEY(pub, rsa);结果是PKCS8的