秘密鍵を読み込んで内容を画面に表示するプログラム
道具
資料
RSA *PEM_read_RSAPrivateKey(FILE *fp, RSA **x, pem_password_cb *cb, void *u);http://www.openssl.org/docs/crypto/pem.html
int RSA_print_fp(FILE *fp, RSA *x, int offset);http://www.openssl.org/docs/crypto/rsa.html
showpKey.cpp
applink.cpp を include しない場合,次のメッセージが表示されて終わる.
OPENSSL_Uplink(1010A000,08): no OPENSSL_Applink
http://rararahp.cool.ne.jp/cgi-bin/lng/vc/vclng.cgi?print+200710/07100049.txt から解決法を得たが,根拠は不明.
#ifdef _DEBUG #pragma comment(lib, "libeay32MDd.lib") #pragma comment(lib, "ssleay32MDd.lib") #else #pragma comment(lib, "libeay32MD.lib") #pragma comment(lib, "ssleay32MD.lib") #endif #include <stdio.h> #include <stdlib.h> #include <openssl/rsa.h> #include <openssl/pem.h> #include <openssl/applink.c> int main ( int argc, char *argv[] ) { int ret; if ( argc > 1 ) { FILE *fp; fopen_s( &fp, argv[1], "r" ); if ( fp != NULL ) { RSA *rsa = PEM_read_RSAPrivateKey( fp, NULL, NULL, NULL ); ret = RSA_print_fp( stderr, rsa, 0 ); fclose( fp ); }else{ perror("読み込み失敗"); } } return 0; }
画面出力内容
Private-Key: (2048 bit) modulus: 00:b9:0f:29:29:5a:c9:c0:4f:f1:e9:56:35:f2:0b: e3:c5:64:06:02:84:bd:3b:94:00:b5:f9:99:54:3b: 72:b2:63:fb:d2:f5:90:73:08:7a:11:51:94:75:e6: 16:56:c8:da:75:4c:3a:a1:2b:76:fb:91:46:8b:4d: d3:8f:71:f4:ad:26:2a:b0:30:d2:85:a0:7d:58:18: bc:b9:b5:db:34:03:9e:cb:b3:5d:96:2d:26:b6:67: 2d:f3:13:ca:bc:a4:3d:75:89:1f:38:8a:d1:0b:d1: d7:96:32:e5:d2:b2:75:4b:f2:ae:bb:92:9d:e6:fc: 4b:10:d7:5d:12:7b:6d:ac:35:a4:30:44:d9:5b:2d: 2b:23:be:42:6d:4c:af:cc:29:c6:99:54:f3:6b:18: f7:5b:3c:cf:71:65:7e:5a:e3:39:00:b1:84:5e:d7: c2:e3:e9:26:2a:45:28:91:15:83:f7:9d:2f:a2:16: ae:8a:58:6e:ba:2a:46:f6:43:3b:49:7a:ae:49:9a: 43:3d:e0:c4:59:34:2e:be:d1:83:30:aa:7a:81:90: 79:fe:13:86:9a:c5:d7:42:c0:4e:6b:40:50:3e:a1: ff:14:6c:36:19:09:99:d7:45:e2:ca:37:5f:57:47: 11:6d:45:74:12:33:76:87:c0:98:0a:21:ae:83:aa: 3e:55 publicExponent: 6557 (0x199d) privateExponent: 00:af:60:f1:2b:4a:71:80:e1:af:6a:ee:a6:9c:4c: 3b:eb:e8:2e:4c:a5:26:6e:2f:07:1d:99:a7:d5:ef: a4:41:0c:e1:c4:5e:fa:45:95:3f:cb:8a:cd:d1:24: 4f:43:ea:94:db:8b:0a:ef:f5:93:c7:8f:92:4e:0f: 81:15:d2:2b:11:a4:e4:7b:8f:21:da:6c:d5:e4:eb: ad:45:23:1c:1a:6a:1c:ad:5e:1f:b0:7b:87:58:e1: af:3c:41:37:85:d6:04:49:ac:27:59:26:e8:63:d3: c9:c5:82:2f:57:a9:c9:63:30:03:05:3b:a7:04:21: 93:c7:6b:77:dd:e6:c7:aa:ce:df:38:83:13:e6:e0: 1b:68:2a:ad:00:07:8a:cb:91:d4:c9:d9:6d:4a:32: 62:15:c6:92:5f:6d:7a:1f:15:7e:2c:c4:d3:cc:16: 29:14:a1:c7:2c:2b:09:47:0a:9f:1c:c4:cd:0c:c9: 65:fa:64:59:b2:a1:e2:6a:bc:dc:b3:4d:23:9a:7f: e5:39:62:87:91:ad:73:fd:cd:3b:42:16:84:5a:bd: e4:91:67:20:e5:c6:c5:aa:0e:df:0b:9c:ae:0e:1a: 94:96:98:24:53:ab:34:dd:be:9a:c9:c6:cc:07:99: c5:ae:69:ca:21:68:ba:59:df:f5:28:ef:0c:b7:01: 93:dd prime1: 00:ea:80:df:ec:f6:a8:7d:0a:97:4a:10:5b:41:42: 69:a6:71:df:f4:d7:68:2e:37:6a:b3:b9:bf:ee:e8: 26:39:2b:fc:bb:a4:51:a3:d1:ab:00:c1:5d:a0:85: 33:21:90:b4:a3:35:13:d5:2e:ff:0f:85:13:cf:4b: 59:3d:2e:6c:47:a6:43:26:4f:73:0d:17:9d:57:90: 28:78:f3:d9:8a:a3:f8:32:79:91:32:ec:07:3b:dc: a6:d2:aa:79:7e:c2:2a:8a:bf:68:9a:13:fe:34:19: 36:0b:96:ac:2e:81:10:15:cc:0b:90:16:b2:69:52: 1e:e3:c0:14:cd:c7:d4:12:bb prime2: 00:ca:05:f8:d9:69:31:f3:79:ac:e6:5b:0e:e1:65: 69:30:bf:79:5c:54:ae:b4:c6:e3:dc:79:d7:87:aa: 2e:e3:9e:f4:fe:94:b0:fb:a2:0b:3d:73:31:18:f3: e1:ed:d6:b9:39:74:52:c0:98:f7:25:24:43:af:9a: 1c:08:1f:52:03:b9:fd:25:3e:e4:fe:ec:a0:fc:c1: e9:7c:a6:9f:39:07:da:f2:19:a2:1c:bd:c4:9d:03: 31:ff:f5:53:b5:a1:bd:74:d5:55:b8:c1:c4:9d:26: 4e:aa:84:72:d9:80:fd:a6:ff:e2:a6:81:bc:90:6b: 99:bd:c0:0f:e4:3f:c6:8a:2f exponent1: 00:cf:1b:bb:2f:91:6b:75:a8:19:77:ea:22:ea:39: 49:ab:70:de:bd:ce:99:f8:53:b0:c5:b1:a3:07:be: 4f:6f:fc:04:ec:4f:42:35:0c:9b:84:15:52:9c:7c: aa:ad:bf:c0:86:9d:67:cc:99:48:b9:d8:12:dc:ac: ef:b4:ff:d9:67:38:2e:e3:c1:f8:90:d0:60:35:b6: 99:e2:e0:a7:a6:03:f3:2c:9e:0a:d6:24:ab:4d:9f: 1c:af:5b:a5:0b:9c:9b:b6:c7:f8:29:20:b0:4a:33: 64:34:52:82:d3:ff:97:7a:84:75:a8:04:1d:be:a9: 64:18:48:63:44:de:ab:cc:73 exponent2: 27:48:7d:cf:26:92:16:65:3c:8f:2d:c7:0a:ae:5d: 94:8c:25:b1:52:f4:90:b4:51:b5:b4:9a:4f:e8:21: 16:e7:8c:0d:45:8e:49:ae:b7:57:74:e1:91:53:75: 68:bb:93:53:7a:69:2f:7b:f3:ee:96:24:32:45:20: 31:d5:e9:7d:b2:e7:5b:1a:e8:de:22:ec:96:80:84: a9:1f:bc:57:06:d6:52:0e:d2:af:f8:14:63:8e:bc: 2f:3b:a6:83:02:b7:0d:81:0d:ef:7d:f3:d3:e8:a4: fc:07:17:9e:e9:9b:52:72:69:18:4b:97:73:43:80: 0c:06:da:ae:6e:b5:9e:17 coefficient: 00:88:70:c9:07:45:1e:bf:dc:e1:1e:b0:0a:c3:93: 86:dc:74:85:73:e4:a4:bb:17:93:3c:0f:1a:74:72: a1:aa:2e:7b:3a:6d:06:61:ea:0d:f8:56:1e:4d:6a: ac:bf:c3:a7:cc:a3:f5:16:31:7c:ea:95:a0:51:ef: 4d:b7:4c:4f:71:a0:88:b0:3c:a5:24:2b:a2:df:86: 8a:6c:f7:00:b5:f5:19:57:f2:21:d5:12:5c:93:a2: e4:d8:5f:1e:06:57:48:31:7b:0b:51:96:b4:84:01: 21:3e:f3:d3:ab:22:60:41:fd:8f:4b:e9:c3:1a:28: b1:30:5f:d9:80:51:b1:86:70