https://mbed-tls.readthedocs.io/en/latest/kb/cryptography/asn1-key-structures-in-der-and-pem/
RSAPrivateKey ::= SEQUENCE { version Version, modulus INTEGER, -- n publicExponentINTEGER, -- e privateExponent INTEGER, -- d prime1INTEGER, -- p prime2INTEGER, -- q exponent1 INTEGER, -- d mod (p-1) exponent2 INTEGER, -- d mod (q-1) coefficient INTEGER, -- (inverse of q) mod p otherPrimeInfos OtherPrimeInfos OPTIONAL }
原始資料:
<RSAKeyValue>
<Modulus>8kssxL1TBONoEV8Kjq+xNYVDKrXmncaUG0TlP2JTsET/slPYu3nbQpt+Ks7JKsBBDuTgB/hlS7THt2TJMDzs1mnD8laa4LWlYA8PDKRuWbtkMzCFqfxsQGmq53kT+KgKAI7QYce8nPS/m99Ta276pUVSntG3ad+s7KFmC1dbxw/sFwXVSBX3TY8QUV8VKls1+9S5qJ/chG2KnXdYNBh9BvajerfZZmc86tLz6qrStm5d/ZaGWvwyO9i6OTiiTOrV5t7YPXFmOVPGyJaiFK9W+XRGEt6DgEslpZgZ4rkvEdfyMEM4+kCq3NrW4iaQa9q0qq7lup8U2+/znqceM6C4dQ==</Modulus>
<Exponent>AQAB</Exponent>
<P>9m0ppTX6tY+PnhDrTAz6zvIUMc8866pZodAhTg3lsF3QmH/98wmmzh26jerf/FZtxpg2u1seuGVf+qH06sNyHF04sOv/x0doFbfuksOLNYpNrCIQeE4TE6ii4ccyLXO99xSfbFDhFS7pc2yHYa8D39rXoI/ok+TOvSMmpv1ySm8=</P>
<Q>+7To5BL7KBLpP1MByH9Yg6v6BkO8yYHVJF6ODJs2/SBRxHOUm4Plm9p8aycfwzxx79X6cAkRX/ixUgXCpHt5+mrv4q5DvSKqJLw3EZh8JDqm67NtAK34Lh3gQ3/RZbJXhIJqE/JmLWh5fdEqFbn7DuymslriBrMHL08LpcYhbVs=</Q>
<DP>CarQpm2Or065eJ77TBl6QWIXzrhtkGU3bPSoSdKbvyZ/B2yF/uHTDGT4K5caQGD3n4HbK9BwTRWVBVUTMZ6HPHufvLkVaLDxcWCs2E8Zh/ksAOO5N68AapYEBc11t3jB7A6ADpTBr74OZHvOd9OQ2FhSezcKDbs9LQhS/NwWfrs=</DP>
<DQ>+EEACiLmcCnmvzwhYBypsoRmPtOEWcKh9BMGS0yzOYks3HOauJ+oUMV3PUADRc5SGdiT/vgSmPNyAJIJ3ayjK+dY3dw+l0afRUgVkFcy6ZCnnYUEF01+oA17aVehsYnqY5k1AqNrP5HxcbRgq7kY8ylZaEPW9gCRL4no1QHLak0=</DQ>
<InverseQ>o8ocxO3xkISM+uWa3IGiSbphUHHGYUBtzFM5nyDOWv+tUqNLbZavv4SvpOemvUbBqDSisnnfbkkLj1L0t7c/2SM1EQC2+Dtdv0OFLx7Spbtsv1oIGLWm0d/vcIs01y0I9hWYuZnMnGzdDXrfsxmP/KbOxGiuXHIQmGgmKJr3Nf8=</InverseQ>
<D>QNL4EVMN6Rrmdu9UpcQ/xy/2PnEYWFIOwhT2uLSX62sqdg2UyOPbU8DCSrW0gKmbPl7hyYAdqdmeLWTbpvpF6z+02xtsqH4w1rhwsFM16vAF6OQsfsQ4OiuLPA7a1wYuVuPewKptvhiFQzDG4tF4YctgRXmadssPOugboyEmPuVwYKbPSFzQQUPZMEn1/FHj9OztMpqXoDZ626DKJuskJVmV3QaPNeGl2p78yAdNQZAjKGxXn/wPV5TJrco4zN/BRnhBeN8HsSm6X8UzPLpFNkyK04UpCSUG1GKI5zf5lWQb0vbsgpfL2/ouCIgDvw4JrbULMmuIorvL+4rtlesEqQ==</D>
</RSAKeyValue>
private.asn1:
# Start with a SEQUENCE
asn1=SEQUENCE:RSAPrivateKey
[RSAPrivateKey]
version=INTEGER:0
modulus=INTEGER:0xf24b2cc4bd5304e368115f0a8eafb13585432ab5e69dc6941b44e53f6253b044ffb253d8bb79db429b7e2acec92ac0410ee4e007f8654bb4c7b764c9303cecd669c3f2569ae0b5a5600f0f0ca46e59bb64333085a9fc6c4069aae77913f8a80a008ed061c7bc9cf4bf9bdf536b6efaa545529ed1b769dfaceca1660b575bc70fec1705d54815f74d8f10515f152a5b35fbd4b9a89fdc846d8a9d775834187d06f6a37ab7d966673cead2f3eaaad2b66e5dfd96865afc323bd8ba3938a24cead5e6ded83d71663953c6c896a214af56f9744612de83804b25a59819e2b92f11d7f2304338fa40aadcdad6e226906bdab4aaaee5ba9f14dbeff39ea71e33a0b875
publicExponent=INTEGER:0x010001
privateExponent=INTEGER:0x40d2f811530de91ae676ef54a5c43fc72ff63e711858520ec214f6b8b497eb6b2a760d94c8e3db53c0c24ab5b480a99b3e5ee1c9801da9d99e2d64dba6fa45eb3fb4db1b6ca87e30d6b870b05335eaf005e8e42c7ec4383a2b8b3c0edad7062e56e3dec0aa6dbe18854330c6e2d17861cb6045799a76cb0f3ae81ba321263ee57060a6cf485cd04143d93049f5fc51e3f4eced329a97a0367adba0ca26eb24255995dd068f35e1a5da9efcc8074d419023286c579ffc0f5794c9adca38ccdfc146784178df07b129ba5fc5333cba45364c8ad38529092506d46288e737f995641bd2f6ec8297cbdbfa2e088803bf0e09adb50b326b88a2bbcbfb8aed95eb04a9
prime1INTEGER=INTEGER:0xf66d29a535fab58f8f9e10eb4c0cfacef21431cf3cebaa59a1d0214e0de5b05dd0987ffdf309a6ce1dba8deadffc566dc69836bb5b1eb8655ffaa1f4eac3721c5d38b0ebffc7476815b7ee92c38b358a4dac2210784e1313a8a2e1c7322d73bdf7149f6c50e1152ee9736c8761af03dfdad7a08fe893e4cebd2326a6fd724a6f
prime2INTEGER=INTEGER:0xfbb4e8e412fb2812e93f5301c87f5883abfa0643bcc981d5245e8e0c9b36fd2051c473949b83e59bda7c6b271fc33c71efd5fa7009115ff8b15205c2a47b79fa6aefe2ae43bd22aa24bc3711987c243aa6ebb36d00adf82e1de0437fd165b25784826a13f2662d68797dd12a15b9fb0eeca6b25ae206b3072f4f0ba5c6216d5b
exponent1=INTEGER:0x09aad0a66d8eaf4eb9789efb4c197a416217ceb86d9065376cf4a849d29bbf267f076c85fee1d30c64f82b971a4060f79f81db2bd0704d1595055513319e873c7b9fbcb91568b0f17160acd84f1987f92c00e3b937af006a960405cd75b778c1ec0e800e94c1afbe0e647bce77d390d858527b370a0dbb3d2d0852fcdc167ebb
exponent2=INTEGER:0xf841000a22e67029e6bf3c21601ca9b284663ed38459c2a1f413064b4cb339892cdc739ab89fa850c5773d400345ce5219d893fef81298f372009209ddaca32be758dddc3e97469f454815905732e990a79d8504174d7ea00d7b6957a1b189ea63993502a36b3f91f171b460abb918f329596843d6f600912f89e8d501cb6a4d
coefficient=INTEGER:0xa3ca1cc4edf190848cfae59adc81a249ba615071c661406dcc53399f20ce5affad52a34b6d96afbf84afa4e7a6bd46c1a834a2b279df6e490b8f52f4b7b73fd923351100b6f83b5dbf43852f1ed2a5bb6cbf5a0818b5a6d1dfef708b34d72d08f61598b999cc9c6cdd0d7adfb3198ffca6cec468ae5c7210986826289af735ff
轉換指令:
openssl asn1parse -genconf private.asn1 -out private.der
格式轉換
openssl rsa -text -inform DER -in private.der
提取公鑰
openssl rsa -in private-key.pem -pubout -out public-key.pem
測試:
https://www.devglan.com/online-tools/rsa-encryption-decryption
留言
張貼留言