{"id":4534,"date":"2020-04-06T17:54:32","date_gmt":"2020-04-06T15:54:32","guid":{"rendered":"http:\/\/www.laurentmarot.fr\/wordpress\/?p=4534"},"modified":"2021-08-17T16:53:38","modified_gmt":"2021-08-17T14:53:38","slug":"mais-pourquoi-ma-cle-commence-toujours-par-migf","status":"publish","type":"post","link":"https:\/\/www.laurentmarot.fr\/wordpress\/?p=4534","title":{"rendered":"Mais pourquoi ma cl\u00e9 commence toujours par MIGf&#8230; ?"},"content":{"rendered":"<p>Read that f&#8230; RFC 1421 : <a href=\"https:\/\/tools.ietf.org\/html\/rfc1421\" target=\"_blank\" rel=\"noopener noreferrer\">Privacy Enhancement for Internet Electronic Mail<\/a><\/p>\n<p>and follow those precious links :<\/p>\n<p><a href=\"https:\/\/lapo.it\/asn1js\" target=\"_blank\" rel=\"noopener\">https:\/\/lapo.it\/asn1js<\/a><br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/seccertenroll\/about-encoded-length-and-value-bytes\" target=\"_blank\" rel=\"noopener\">https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/seccertenroll\/about-encoded-length-and-value-bytes<\/a><br \/>\n<a href=\"http:\/\/javadoc.iaik.tugraz.at\/iaik_jce\/current\/iaik\/x509\/PublicKeyInfo.html\" target=\"_blank\" rel=\"noopener\">http:\/\/javadoc.iaik.tugraz.at\/iaik_jce\/current\/iaik\/x509\/PublicKeyInfo.html<\/a><br \/>\n<a href=\"https:\/\/medium.com\/@bn121rajesh\/understanding-rsa-public-key-70d900b1033c\" target=\"_blank\" rel=\"noopener\">https:\/\/medium.com\/@bn121rajesh\/understanding-rsa-public-key-70d900b1033c<\/a><\/p>\n<pre># Generate 1024 bit Private key\r\n$ openssl genrsa -out myprivate.pem 1024\r\n# Separate the public part from the Private key file.\r\n$ openssl rsa -in myprivate.pem -pubout &gt; mypublic.pem\r\n# Display the contents of private key\r\n$ cat myprivate.pem\r\n\r\n-----BEGIN RSA PRIVATE KEY-----\r\nMIICXQIBAAKBgQDRFNU++93aEvz3cV8LSUP9ib3iUxT7SufdVXcgVFK9M3BYzvro\r\nA1uO\/parFOJABTkNhTPPP\/6mjrU2CPEZJ1zIkpaSNJrrhpp\/rNMO9nyLYPGs9Mfd\r\nBiWUPmHW5mY1oD0ye4my0tEsHOlgHC8AhA8OtiHr6IY0agXmH\/y5YmSWbwIDAQAB\r\nAoGAAj\/IH3pUI6FqqTrF+\/gYzCRsL4AXTLC8l8vwkR93GGPyRHJNjqtik8I3WrXJ\r\nzUiBGZ0iNouIsL\/+QQuNlGiw\/c5i2X3nTntREDS9xs2M0x+MWD\/5qI1sn0Qk0HNP\r\nBbDczlvO8wXNFGIHiTiPVEawoeNwhMqJDyGcbsEOZp2pLokCQQDvlMBU6dOeOP9a\r\njnENFSlrvzNR0nugFeoGmfq6s4Czz2QtUd9baKqBfEBSdJskwFVHgxbFA1Dc7iFu\r\nrJkoQEeFAkEA32j9ibSVryxLvWUZngKNwo2xE+wcYDAYVBMsYC3OBU3FXhVkFD06\r\nZVnJsY\/4bd2VdQI+bI2KV99aHutMJG2WYwJABMn2ZjweTMVa5VZ\/kAFiSJMT1Yjd\r\ni7+kY+lkB6Na6T02BWnjixI2hkwThRJrn3pwufM2201Lqn7gEDRHA3T1eQJBAKZG\r\n1RUNo6558HEo8vUIf4vCu33RaJkqkqDYmFmJHeISrQfGMfNiUrkmJ5iRR9w1ZExu\r\n\/Bj9C281XDTQ+Z3PNnMCQQCan+pvj0OZH6o0PAMJGBBwRECPpfZ6mUjwA2YD3g61\r\nMHjtIYmKKGmn64Qs8zQ4mNEDboQqyaov3Ij\/I6c0ZQlc\r\n-----END RSA PRIVATE KEY-----\r\n\r\n<\/pre>\n<p><strong>Privacy Enhanced Mail (PEM)<\/strong><\/p>\n<p>Privacy Enhanced Mail (PEM) is a Base64 encoded Distinguished Encoding Rules(DER)<br \/>\nPEM file is human readable as it uses 64 printable characters for encoding.<br \/>\nIt is easy to share PEM file.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Display the contents of public key PEM file<\/strong><\/p>\n<pre># Display the contents of public key PEM file\r\n$ cat mypublic.pem\r\n\r\n-----BEGIN PUBLIC KEY-----\r\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDRFNU++93aEvz3cV8LSUP9ib3i\r\nUxT7SufdVXcgVFK9M3BYzvroA1uO\/parFOJABTkNhTPPP\/6mjrU2CPEZJ1zIkpaS\r\nNJrrhpp\/rNMO9nyLYPGs9MfdBiWUPmHW5mY1oD0ye4my0tEsHOlgHC8AhA8OtiHr\r\n6IY0agXmH\/y5YmSWbwIDAQAB\r\n-----END PUBLIC KEY-----<\/pre>\n<p>&nbsp;<\/p>\n<p><strong><a name=\"DER\"><\/a>Distinguished Encoding Rules (DER) format of public key<\/strong><\/p>\n<p>DER is encoded in Type-Length-Value (TLV) format.<br \/>\nDER is in binary format for PEM file and follows certain structure for public key.<\/p>\n<pre># Convert PEM file to DER format using openssl rsa\r\n$ openssl rsa -pubin -inform PEM -in mypublic.pem -outform DER -out mypublic.der\r\n# Dump the DER file in hex format.\r\n$ xxd -g 1 -u mypublic.der | cut -c -57\r\n00000000: 30 81 9F 30 0D 06 09 <span style=\"color: #0000ff;\">2A 86 48 86 F7 0D 01 01 01<\/span>\r\n00000010: 05 00 03 81 8D 00 30 81 89 02 81 81 <span style=\"color: #008000;\">00 D1 14 D5<\/span>\r\n<span style=\"color: #008000;\">00000020: 3E FB DD DA 12 FC F7 71 5F 0B 49 43 FD 89 BD E2<\/span>\r\n<span style=\"color: #008000;\">00000030: 53 14 FB 4A E7 DD 55 77 20 54 52 BD 33 70 58 CE<\/span>\r\n<span style=\"color: #008000;\">00000040: FA E8 03 5B 8E FE 96 AB 14 E2 40 05 39 0D 85 33<\/span>\r\n<span style=\"color: #008000;\">00000050: CF 3F FE A6 8E B5 36 08 F1 19 27 5C C8 92 96 92<\/span>\r\n<span style=\"color: #008000;\">00000060: 34 9A EB 86 9A 7F AC D3 0E F6 7C 8B 60 F1 AC F4<\/span>\r\n<span style=\"color: #008000;\">00000070: C7 DD 06 25 94 3E 61 D6 E6 66 35 A0 3D 32 7B 89<\/span>\r\n<span style=\"color: #008000;\">00000080: B2 D2 D1 2C 1C E9 60 1C 2F 00 84 0F 0E B6 21 EB<\/span>\r\n<span style=\"color: #008000;\">00000090: E8 86 34 6A 05 E6 1F FC B9 62 64 96 6F<\/span> 02 03<span style=\"color: #993300;\"> 01<\/span>\r\n000000a0: <span style=\"color: #993300;\">00 01<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Structured DER file content<\/strong><\/p>\n<pre>1:30 81 9F \/\/ Type: 30 (SEQUENCE) Length: 0x9F\r\n2:| 30 0D \/\/ Type: 30 (SEQUENCE) Length: 0x0D\r\n3:| | 06 09 \/\/ Type: 06 (OBJECT_IDENTIFIER) Length: 0x09\r\n4:| | -<span style=\"color: #0000ff;\"> 2A 86 48<\/span> \/\/ 9 bytes OID value. HEX encoding of\r\n5:| | - <span style=\"color: #0000ff;\">86 F7 0D<\/span> \/\/ <span style=\"color: #0000ff;\">1.2.840.113549.1.1.1<\/span>\r\n6:| | - <span style=\"color: #0000ff;\">01 01 01<\/span>\r\n7:| | 05 00 \/\/ Type: 05 (NULL) Length: 0x00\r\n8:| 03 81 8D \/\/ Type: 03 (BIT STRING) Length: 0x8D\r\n9:| | - 00 \/\/ Number of unused bits in last content byte\r\n10:| | 30 81 89 \/\/ Type: 30 (SEQUENCE) Length: 0x89\r\n11:| | | 02 81 81 \/\/ Type: 02 (INTEGER) Length: 0x81\r\n12:| | | -<span style=\"color: #008000;\"> 00<\/span> \/\/ Leading ZERO of integer\r\n13:| | | - <span style=\"color: #008000;\">D1 14 D5 3E FB DD DA 12 FC F7 71 5F 0B 49 43 FD<\/span>\r\n14:| | | - <span style=\"color: #008000;\">89 BD E2 53 14 FB 4A E7 DD 55 77 20 54 52 BD 33<\/span>\r\n15:| | | - <span style=\"color: #008000;\">70 58 CE FA E8 03 5B 8E FE 96 AB 14 E2 40 05 39<\/span>\r\n16:| | | - <span style=\"color: #008000;\">0D 85 33 CF 3F FE A6 8E B5 36 08 F1 19 27 5C C8<\/span>\r\n17:| | | - <span style=\"color: #008000;\">92 96 92 34 9A EB 86 9A 7F AC D3 0E F6 7C 8B 60<\/span>\r\n18:| | | - <span style=\"color: #008000;\">F1 AC F4 C7 DD 06 25 94 3E 61 D6 E6 66 35 A0 3D<\/span>\r\n19:| | | - <span style=\"color: #008000;\">32 7B 89 B2 D2 D1 2C 1C E9 60 1C 2F 00 84 0F 0E<\/span>\r\n20:| | | - <span style=\"color: #008000;\">B6 21 EB E8 86 34 6A 05 E6 1F FC B9 62 64 96 6F<\/span>\r\n21:| | | 02 03 \/\/ Type: 02 (INTEGER) Length: 0x3\r\n22:| | | -<span style=\"color: #993300;\"> 01 00 01<\/span> \/\/ Public Exponent. Hex for 65537<\/pre>\n<p>&nbsp;<\/p>\n<p>DER file contains Object Identifier, Modulus and Public exponent in HEX format.<\/p>\n<p><span style=\"color: #0000ff;\">Lines 4, 5, 6 is the HEX encoding of OID<\/span>.<br \/>\n<span style=\"color: #008000;\">Lines 13 to 20 is the modulus (n).<\/span><br \/>\n<span style=\"color: #993300;\">Line 22 is the public exponent.<\/span><\/p>\n<p>You can also have a look at <a href=\"https:\/\/lapo.it\/asn1js\/#MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDRFNU--93aEvz3cV8LSUP9ib3iUxT7SufdVXcgVFK9M3BYzvroA1uO_parFOJABTkNhTPPP_6mjrU2CPEZJ1zIkpaSNJrrhpp_rNMO9nyLYPGs9MfdBiWUPmHW5mY1oD0ye4my0tEsHOlgHC8AhA8OtiHr6IY0agXmH_y5YmSWbwIDAQAB\" target=\"_blank\" rel=\"noopener\">Lapo ASN.1 javascript decoder<\/a> :<\/p>\n<div id=\"attachment_4826\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.laurentmarot.fr\/wordpress\/wp-content\/uploads\/2020\/04\/Capture-du-2021-08-17-16-42-04.png\" rel=\"lightbox[4534]\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4826\" class=\"size-medium wp-image-4826\" src=\"https:\/\/www.laurentmarot.fr\/wordpress\/wp-content\/uploads\/2020\/04\/Capture-du-2021-08-17-16-42-04-300x110.png\" alt=\"Javascript ASN.1 decoder\" width=\"300\" height=\"110\" srcset=\"https:\/\/www.laurentmarot.fr\/wordpress\/wp-content\/uploads\/2020\/04\/Capture-du-2021-08-17-16-42-04-300x110.png 300w, https:\/\/www.laurentmarot.fr\/wordpress\/wp-content\/uploads\/2020\/04\/Capture-du-2021-08-17-16-42-04-1024x376.png 1024w, https:\/\/www.laurentmarot.fr\/wordpress\/wp-content\/uploads\/2020\/04\/Capture-du-2021-08-17-16-42-04-768x282.png 768w, https:\/\/www.laurentmarot.fr\/wordpress\/wp-content\/uploads\/2020\/04\/Capture-du-2021-08-17-16-42-04.png 1208w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-4826\" class=\"wp-caption-text\">Javascript ASN.1 decoder<\/p><\/div>\n<p><strong>Modulus and Public exponent from public key using openssl<\/strong><\/p>\n<pre># Get Modulus and Public exponent from public PEM file\r\n$ openssl rsa -pubin -inform PEM -text -noout &lt; mypublic.pem\r\n\r\nPublic-Key: (1024 bit)\r\nModulus:\r\n<span style=\"color: #008000;\">00:d1:14:d5:3e:fb:dd:da:12:fc:f7:71:5f:0b:49:<\/span>\r\n<span style=\"color: #008000;\">43:fd:89:bd:e2:53:14:fb:4a:e7:dd:55:77:20:54:<\/span>\r\n<span style=\"color: #008000;\">52:bd:33:70:58:ce:fa:e8:03:5b:8e:fe:96:ab:14:<\/span>\r\n<span style=\"color: #008000;\">e2:40:05:39:0d:85:33:cf:3f:fe:a6:8e:b5:36:08:<\/span>\r\n<span style=\"color: #008000;\">f1:19:27:5c:c8:92:96:92:34:9a:eb:86:9a:7f:ac:<\/span>\r\n<span style=\"color: #008000;\">d3:0e:f6:7c:8b:60:f1:ac:f4:c7:dd:06:25:94:3e:<\/span>\r\n<span style=\"color: #008000;\">61:d6:e6:66:35:a0:3d:32:7b:89:b2:d2:d1:2c:1c:<\/span>\r\n<span style=\"color: #008000;\">e9:60:1c:2f:00:84:0f:0e:b6:21:eb:e8:86:34:6a:<\/span>\r\n<span style=\"color: #008000;\">05:e6:1f:fc:b9:62:64:96:6f<\/span>\r\nExponent: 65537 (<span style=\"color: #993300;\">0x10001<\/span>)<\/pre>\n<p>Exponent and modulus printed by openssl rsa matches with the Public exponent and modulus from DER file content.<\/p>\n<p>More information on recommended syntax for interchanging RSA public keys between implementations is given in Appendix A.1.1 of <a href=\"https:\/\/datatracker.ietf.org\/doc\/html\/rfc3447\" target=\"_blank\" rel=\"noopener\">rfc3447<\/a> ( PKCS#1);<\/p>\n<div id=\"attachment_4818\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.laurentmarot.fr\/wordpress\/wp-content\/uploads\/2020\/04\/Capture-du-2021-08-05-22-05-36.png\" rel=\"lightbox[4534]\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4818\" class=\"size-medium wp-image-4818\" src=\"https:\/\/www.laurentmarot.fr\/wordpress\/wp-content\/uploads\/2020\/04\/Capture-du-2021-08-05-22-05-36-300x285.png\" alt=\"RSA key representation\" width=\"300\" height=\"285\" srcset=\"https:\/\/www.laurentmarot.fr\/wordpress\/wp-content\/uploads\/2020\/04\/Capture-du-2021-08-05-22-05-36-300x285.png 300w, https:\/\/www.laurentmarot.fr\/wordpress\/wp-content\/uploads\/2020\/04\/Capture-du-2021-08-05-22-05-36.png 643w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-4818\" class=\"wp-caption-text\">RSA key representation<\/p><\/div>\n<p>&nbsp;<\/p>\n<p><strong>Object Identifier<\/strong><\/p>\n<p>OID describes the object. It is a series of nodes separated by period.<\/p>\n<p>OID Value: <span style=\"color: #0000ff;\">1.2.840.113549.1.1.1<\/span><\/p>\n<p>OID description: Identifier for RSA encryption for use with Public Key Cryptosystem One defined by RSA Inc.<\/p>\n<p>OID Encoding rules:<\/p>\n<p>1 &#8211; The first two nodes of the OID are encoded onto a single byte. The first node is multiplied by the decimal 40 and the result is added to the value of the second node.<br \/>\n2 &#8211; Node values less than or equal to 127 are encoded on one byte.<br \/>\n3 &#8211; Node values greater than or equal to 128 are encoded on multiple bytes. Bit 7 of all bytes except the rightmost byte is set to one. Bits 0 through 6 of each byte contains the encoded value.<\/p>\n<div id=\"attachment_4823\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.laurentmarot.fr\/wordpress\/wp-content\/uploads\/2020\/04\/1Apm4zQV13v6ogX1efNuODg.png\" rel=\"lightbox[4534]\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4823\" class=\"size-medium wp-image-4823\" src=\"https:\/\/www.laurentmarot.fr\/wordpress\/wp-content\/uploads\/2020\/04\/1Apm4zQV13v6ogX1efNuODg-300x200.png\" alt=\"OID Encoding Example \u00a9 Rajesh Bondugula\" width=\"300\" height=\"200\" srcset=\"https:\/\/www.laurentmarot.fr\/wordpress\/wp-content\/uploads\/2020\/04\/1Apm4zQV13v6ogX1efNuODg-300x200.png 300w, https:\/\/www.laurentmarot.fr\/wordpress\/wp-content\/uploads\/2020\/04\/1Apm4zQV13v6ogX1efNuODg.png 700w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-4823\" class=\"wp-caption-text\">OID Encoding Example \u00a9 Rajesh Bondugula<\/p><\/div>\n<p>&nbsp;<\/p>\n<p><strong>Representing length in ASN.1 encoding<\/strong><\/p>\n<p>If number of value bytes is &lt; 128 (0x80) then length is represented in 1 byte. In this case most significant bit is 0. (Ex: Line 2: 0x81=10000001 =&gt; 1 octet, Line 3 in structured DER <a href=\"#DER\">content above<\/a>)<\/p>\n<p>If number of value bytes is &gt;= 128 (0x80) then length is represented in multiple bytes. Most significant bit (bit 7) of first byte is 1 indicating multiple byte length. Bits 0\u20136 represent number of subsequent bytes for length. (Ex:\u00a0 Line 1: 0x82=10000010 =&gt; 2 octets, Line 4 in structured DER <a href=\"#DER\">content above<\/a>)<\/p>\n<p>&nbsp;<\/p>\n<p><strong>References<\/strong><\/p>\n<p>DER encoding of ASN.1 types (MSDN)<br \/>\nPublic Key Info structure (Java doc)<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\">[ajout de ao\u00fbt 2021 suite plaintes]<\/span><\/p>\n<p>&#8211; Mais du coup &#8230; tu n&rsquo;as pas r\u00e9pondu\u00a0 la question ?<br \/>\n[lm] C&rsquo;est pas faux, mais si tu <a href=\"https:\/\/fr.wikipedia.org\/wiki\/Base64\" target=\"_blank\" rel=\"noopener\">r\u00e9vises le fonctionnement de l&rsquo;encodage base 64<\/a>, \u00e0 partir d&rsquo;un contenu DER qui commence toujours par la m\u00eame syntaxe:<\/p>\n<pre>xxd -r -p &lt;&lt;&lt;30819F | base64\r\n<span style=\"color: #339966;\"><strong>MIGf<\/strong><\/span><\/pre>\n<p>&nbsp;<\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>Read that f&#8230; RFC 1421 : Privacy Enhancement for Internet Electronic Mail and follow those precious links : https:\/\/lapo.it\/asn1js https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/seccertenroll\/about-encoded-length-and-value-bytes http:\/\/javadoc.iaik.tugraz.at\/iaik_jce\/current\/iaik\/x509\/PublicKeyInfo.html https:\/\/medium.com\/@bn121rajesh\/understanding-rsa-public-key-70d900b1033c # Generate 1024 bit Private key $ openssl genrsa -out myprivate.pem 1024 # Separate the public part from the Private key file. $ openssl rsa -in myprivate.pem -pubout &gt; mypublic.pem # Display the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51,34],"tags":[],"_links":{"self":[{"href":"https:\/\/www.laurentmarot.fr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/4534"}],"collection":[{"href":"https:\/\/www.laurentmarot.fr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laurentmarot.fr\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laurentmarot.fr\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laurentmarot.fr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4534"}],"version-history":[{"count":28,"href":"https:\/\/www.laurentmarot.fr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/4534\/revisions"}],"predecessor-version":[{"id":4828,"href":"https:\/\/www.laurentmarot.fr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/4534\/revisions\/4828"}],"wp:attachment":[{"href":"https:\/\/www.laurentmarot.fr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4534"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laurentmarot.fr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4534"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laurentmarot.fr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4534"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}