RSAPrivateKey ::= SEQUENCE { versionVersion, modulus INTEGER, -- n publicExponent INTEGER, -- e privateExponent INTEGER, -- d prime1 INTEGER, -- p prime2 INTEGER, -- q exponent1 INTEGER, -- d mod (p-1) exponent2 INTEGER, -- d mod (q-1) coefficient INTEGER, -- (inverse of q) mod p otherPrimeInfos OtherPrimeInfos OPTIONAL }
Last login: Sat Jul 16 18:45:25 on ttys003 (base) wenhui@Harrys-MacBook-Pro ~ % echo -n 'MIICWgIBAAKBgQCcSnm2TgLST457G9sUfy9qyITaX1gGHTYzpe364ho1ayOF0f2U EDJVO7eUxKHm8qQIoFU6xjdjMZGxaODrVQMqkbBn3EWzCdW2R4B0Kp/YUFlGQoWS KFUin0D7uWn2DM4jPcpTTOX0Og2VSe0SGQ0spn++rF7buHqxv3c12DTVowIDAQAB An8FUfFk+h5DCnI84yOR/MJXTenKF3TDCak8YfvcadXoRL1eh6LQ+bwqmEuC6Xe9 9xbC60SNu59LnIjrXIICXCuazAW8JEpQqYoijyAsX7LiFctvKwDh7DP+9g3/4+vN 08C1o+38/Yl/aAZmUHiyZxj1/TPu25fXiHPWEeTXOo3xAkEAx2j4EbnWZuARrtAi i7T5j2IuhT4UsD+U0YWjFnwQiWpwJ5F67uISFqA6MHn2v0LfVE5eADX9kPYa2FcZ s0T1SQJBAMik7REmT1d9snwMHS0qqlkeZGCu7MEcJEHAsmIcpZBo6q+CtPJBFikO VVPK6H01IM97ApActK2OuerbZBUhb4sCQFJfShoIakiUxrkvwRV07KIOLKldu64S lab3TSc8mJgrH6k4r09+k3pFNcRQnVzkgtyQgsQTiWsYPn6ffD5RfgECQQCrtOCg PY3GzO4y1FcfsRSJIcY7K1e3RzMMBjFiXyuc8vxsaMobS3IAfqCtDcd6Zz4F8TpX RAmnQa5/e3Mh1jRTAkApRCqIkHmCu4MA3bNSImZ6Ll7gdB8Ppcu1aYqmLP0XpEvL VmTRs4AtlHEOi1ZdGuNcoAzIcrK9h4sVnXRo+JTJ' | base64 -d | hexdump 0000000 30 82 02 5a 02 01 00 02 81 81 00 9c 4a 79 b6 4e 0000010 02 d2 4f 8e 7b 1b db 14 7f 2f 6a c8 84 da 5f 58 0000020 06 1d 36 33 a5 ed fa e2 1a 35 6b 23 85 d1 fd 94 0000030 10 32 55 3b b7 94 c4 a1 e6 f2 a4 08 a0 55 3a c6 0000040 37 63 31 91 b1 68 e0 eb 55 03 2a 91 b0 67 dc 45 0000050 b3 09 d5 b6 47 80 74 2a 9f d8 50 59 46 42 85 92 0000060 28 55 22 9f 40 fb b9 69 f6 0c ce 23 3d ca 53 4c 0000070 e5 f4 3a 0d 95 49 ed 12 19 0d 2c a6 7f be ac 5e 0000080 db b8 7a b1 bf 77 35 d8 34 d5 a3 02 03 01 00 01 0000090 02 7f 05 51 f1 64 fa 1e 43 0a 72 3c e3 23 91 fc 00000a0 c2 57 4d e9 ca 17 74 c3 09 a9 3c 61 fb dc 69 d5 00000b0 e8 44 bd 5e 87 a2 d0 f9 bc 2a 98 4b 82 e9 77 bd 00000c0 f7 16 c2 eb 44 8d bb 9f 4b 9c 88 eb 5c 82 02 5c 00000d0 2b 9a cc 05 bc 24 4a 50 a9 8a 22 8f 20 2c 5f b2 00000e0 e2 15 cb 6f 2b 00 e1 ec 33 fe f6 0d ff e3 eb cd 00000f0 d3 c0 b5 a3 ed fc fd 89 7f 68 06 66 50 78 b2 67 0000100 18 f5 fd 33 ee db 97 d7 88 73 d6 11 e4 d7 3a 8d 0000110 f1 02 41 00 c7 68 f8 11 b9 d6 66 e0 11 ae d0 22 0000120 8b b4 f9 8f 62 2e 85 3e 14 b0 3f 94 d1 85 a3 16 0000130 7c 10 89 6a 70 27 91 7a ee e2 12 16 a0 3a 30 79 0000140 f6 bf 42 df 54 4e 5e 00 35 fd 90 f6 1a d8 57 19 0000150 b3 44 f5 49 02 41 00 c8 a4 ed 11 26 4f 57 7d b2 0000160 7c 0c 1d 2d 2a aa 59 1e 64 60 ae ec c1 1c 24 41 0000170 c0 b2 62 1c a5 90 68 ea af 82 b4 f2 41 16 29 0e 0000180 55 53 ca e8 7d 35 20 cf 7b 02 90 1c b4 ad 8e b9 0000190 ea db 64 15 21 6f 8b 02 40 52 5f 4a 1a 08 6a 48 00001a0 94 c6 b9 2f c1 15 74 ec a2 0e 2c a9 5d bb ae 12 00001b0 95 a6 f7 4d 27 3c 98 98 2b 1f a9 38 af 4f 7e 93 00001c0 7a 45 35 c4 50 9d 5c e4 82 dc 90 82 c4 13 89 6b 00001d0 18 3e 7e 9f 7c 3e 51 7e 01 02 41 00 ab b4 e0 a0 00001e0 3d 8d c6 cc ee 32 d4 57 1f b1 14 89 21 c6 3b 2b 00001f0 57 b7 47 33 0c 06 31 62 5f 2b 9c f2 fc 6c 68 ca 0000200 1b 4b 72 00 7e a0 ad 0d c7 7a 67 3e 05 f1 3a 57 0000210 44 09 a7 41 ae 7f 7b 73 21 d6 34 53 02 40 29 44 0000220 2a 88 90 79 82 bb 83 00 dd b3 52 22 66 7a 2e 5e 0000230 e0 74 1f 0f a5 cb b5 69 8a a6 2c fd 17 a4 4b cb 0000240 56 64 d1 b3 80 2d 94 71 0e 8b 56 5d 1a e3 5c a0 0000250 0c c8 72 b2 bd 87 8b 15 9d 74 68 f8 94 c9 000025e
先声明一下填充的格式参数吧
前缀,例如02、30,一定存在
辅助参数,例如81、82,可能存在
长度,数据十六进制下字节数的十六进制,一定存在
具体的,当我们有n、e、d…等数据等时候,要如何填充呢?
1 2 3 4 5 6 7 8 9 10 11 12
RSAPrivateKey ::= SEQUENCE { versionVersion, modulus INTEGER, -- n publicExponent INTEGER, -- e privateExponent INTEGER, -- d prime1 INTEGER, -- p prime2 INTEGER, -- q exponent1 INTEGER, -- d mod (p-1) exponent2 INTEGER, -- d mod (q-1) coefficient INTEGER, -- (inverse of q) mod p otherPrimeInfos OtherPrimeInfos OPTIONAL }
n = 0x9c4a79b64e02d24f8e7b1bdb147f2f6ac884da5f58061d3633a5edfae21a356b2385d1fd941032553bb794c4a1e6f2a408a0553ac637633191b168e0eb55032a91b067dc45b309d5b64780742a9fd85059464285922855229f40fbb969f60cce233dca534ce5f43a0d9549ed12190d2ca67fbeac5edbb87ab1bf7735d834d5a3
def construct(num, T=0): if T == 0: num = shex(num) if int(num[:2], 16) >= 0x80: num = '00' + num LEN = hlen(num) if int(LEN, 16) >= 0x80: if int(hlen(LEN), 16) == 1: return '81' + LEN + num if int(hlen(LEN), 16) == 2: return '82' + LEN + num return hlen(num) + num
def hpad(data, T=0): # 默认不是文件头, 是就T=1 return '02' + construct(data, T) if T == 0 else '30' + construct(data, T)
n = 151036135413139226687867011199700639084856588533884431118047808395603993635242690166659649156476428533386350427603713487259266502837260466348398817558768025404903682189934563578605367223796247470920497617904900418615352839562681665973088711089128789315193951623751145385357347144960284983398745189236464272961 e = 65537 d = 66980701583036734736960294391078312622827897052791813876359026247918495979594634282982071853820451331222681673373427663666376575651344098661059603483956134335089509308267535247063609325195212704938058730366660923446510585605669518343968880619319880983999690229384618652977238799179660803464509489433199564801 q = 12112790828812363063315417237469719611888243756064158121348026938824270601623590308149025542977097905953795136774300936003505715307199422663647014200158449 p = 12469144192094336933187534132907623337514842804208163244218540727384104398951558782195384932941310035462094951428865175221316720981428462265191789302379089 dq = 11498252026215339897996227126317442002148273807959830401838708697653776075624560175939807697631738024706616156507054180549156927547667584459935731684701121 dp = 11263269100321843418340309033584057768246046953115325020896491943793759194249558697334095131684279304657225064156696057310019203890620314290203835007881649 qi = 230121277324731969722527349653498610340545443290131539298194061889386294775484298329444143510348368415044353961014184478364151608769305026976078967964618