{"id":2323,"date":"2024-11-29T18:35:38","date_gmt":"2024-11-29T10:35:38","guid":{"rendered":"https:\/\/pjq.me\/?p=2323"},"modified":"2025-11-13T13:25:53","modified_gmt":"2025-11-13T05:25:53","slug":"how-to-check-the-pqnphi_ned","status":"publish","type":"post","link":"https:\/\/pjq.me\/?p=2323","title":{"rendered":"How to check the RSA p,q,N,phi_N,e,d"},"content":{"rendered":"\n<p>As we know the RSA certificates<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>we will choose two primes p,q<\/li>\n\n\n\n<li>N=p*q<\/li>\n\n\n\n<li>phi_N = (p-1)*(q-1)<\/li>\n\n\n\n<li>Then choose e, e.g. 65537<\/li>\n\n\n\n<li>Then calculate the d, e*d % phi_N = 1<\/li>\n\n\n\n<li>Then we have the public key (e, N), private key (d, N)<\/li>\n<\/ol>\n\n\n\n<p>Now we got the certificates from let&#8217;s encrypt, so how can be get those values<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>cert1.pem<\/li>\n\n\n\n<li>chain1.pem<\/li>\n\n\n\n<li>fullchain1.pem<\/li>\n\n\n\n<li>privkey1.pem<\/li>\n<\/ol>\n\n\n\n<p>Here is one Python script that print all those details.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from cryptography import x509\nfrom cryptography.hazmat.backends import default_backend\nfrom cryptography.hazmat.primitives import serialization\n\ndef load_certificate(file_path):\n    with open(file_path, 'rb') as f:\n        cert_data = f.read()\n    return x509.load_pem_x509_certificate(cert_data, default_backend())\n\ndef load_private_key(file_path):\n    with open(file_path, 'rb') as f:\n        key_data = f.read()\n    return serialization.load_pem_private_key(key_data, password=None, backend=default_backend())\n\ndef display_certificate_details(cert):\n    print(\"Issuer:\", cert.issuer)\n    print(\"Subject:\", cert.subject)\n    print(\"Serial Number:\", cert.serial_number)\n    print(\"Not Before:\", cert.not_valid_before)\n    print(\"Not After:\", cert.not_valid_after)\n    print(\"Public Key:\", cert.public_key())\n\ndef display_private_key_details(key):\n    print(\"Private Key Type:\", type(key))\n    print(\"Private Key:\", key)\n\n# Load and display details for each file\ncert1 = load_certificate('cert1.pem')\nchain1 = load_certificate('chain1.pem')\nfullchain1 = load_certificate('fullchain1.pem')\nprivkey1 = load_private_key('privkey1.pem')\n\nprint(\"Certificate 1 Details:\")\ndisplay_certificate_details(cert1)\n\nprint(\"\\nChain 1 Details:\")\ndisplay_certificate_details(chain1)\n\nprint(\"\\nFull Chain 1 Details:\")\ndisplay_certificate_details(fullchain1)\n\nprint(\"\\nPrivate Key 1 Details:\")\ndisplay_private_key_details(privkey1)\n\n\nfrom cryptography.hazmat.primitives import serialization\nfrom cryptography.hazmat.backends import default_backend\n\ndef load_private_key(file_path):\n    with open(file_path, 'rb') as f:\n        key_data = f.read()\n    return serialization.load_pem_private_key(key_data, password=None, backend=default_backend())\n\ndef display_rsa_parameters(key):\n    if key.private_numbers():\n        private_numbers = key.private_numbers()\n        public_numbers = private_numbers.public_numbers\n\n        p = private_numbers.p\n        q = private_numbers.q\n        d = private_numbers.d\n        e = public_numbers.e\n        N = public_numbers.n\n        phi_N = (p - 1) * (q - 1)\n\n        print(\"p:\", p)\n        print(\"q:\", q)\n        print(\"e:\", e)\n        print(\"d:\", d)\n        print(\"N:\", N)\n        print(\"phi_N:\", phi_N)\n    else:\n        print(\"The key is not an RSA private key.\")\n\n# Load the private key\nprivkey1 = load_private_key('privkey1.pem')\n\n# Display RSA parameters\ndisplay_rsa_parameters(privkey1)<\/code><\/pre>\n\n\n\n<p>And here is the output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Certificate 1 Details:\nIssuer: &lt;Name(C=US,O=Let's Encrypt,CN=R3)>\nSubject: &lt;Name(CN=*.pjq.me)>\nSerial Number: 399357001611271868934008942535231577601291\n\/Users\/i329817\/SAPDevelop\/workspace\/SECulum-Crypto-Examples\/Other\/CA.py:19: CryptographyDeprecationWarning: Properties that return a na\u00efve datetime object have been deprecated. Please switch to not_valid_before_utc.\n  print(\"Not Before:\", cert.not_valid_before)\nNot Before: 2024-03-11 03:37:02\n\/Users\/i329817\/SAPDevelop\/workspace\/SECulum-Crypto-Examples\/Other\/CA.py:20: CryptographyDeprecationWarning: Properties that return a na\u00efve datetime object have been deprecated. Please switch to not_valid_after_utc.\n  print(\"Not After:\", cert.not_valid_after)\nNot After: 2024-06-09 03:37:01\nPublic Key: &lt;cryptography.hazmat.bindings._rust.openssl.rsa.RSAPublicKey object at 0x101310310>\n\nChain 1 Details:\nIssuer: &lt;Name(C=US,O=Internet Security Research Group,CN=ISRG Root X1)>\nSubject: &lt;Name(C=US,O=Let's Encrypt,CN=R3)>\nSerial Number: 192961496339968674994309121183282847578\nNot Before: 2020-09-04 00:00:00\nNot After: 2025-09-15 16:00:00\nPublic Key: &lt;cryptography.hazmat.bindings._rust.openssl.rsa.RSAPublicKey object at 0x101310310>\n\nFull Chain 1 Details:\nIssuer: &lt;Name(C=US,O=Let's Encrypt,CN=R3)>\nSubject: &lt;Name(CN=*.pjq.me)>\nSerial Number: 399357001611271868934008942535231577601291\nNot Before: 2024-03-11 03:37:02\nNot After: 2024-06-09 03:37:01\nPublic Key: &lt;cryptography.hazmat.bindings._rust.openssl.rsa.RSAPublicKey object at 0x1013102f0>\n\nPrivate Key 1 Details:\nPrivate Key Type: &lt;class 'cryptography.hazmat.bindings._rust.openssl.rsa.RSAPrivateKey'>\nPrivate Key: &lt;cryptography.hazmat.bindings._rust.openssl.rsa.RSAPrivateKey object at 0x1013101f0>\np: 132069789892654411168004522386293936563648260984708049888769058861400033840104922637240827355145535778467721990046061228393420363010924409941513508800258809981119101399937003195217979917259199066675447728576676098948661691324234988484581514373041670098119069924124636404134462689209640493314790132976282083611\nq: 137105056982080406391028823084893501194543535606308088202698272087931645688882684542797221955650442538986772234601648478841035329665841202081550877179575957078786677686845060335508172755008305533505548942627696405948787947081088462002379085459968945063951380151782547161878405562777603813013479678683689059989\ne: 65537\nd: 756214848412734766389636904239299485009061447036919688389891952047609574545734290864923373793452280368637781527992131423339716753716888185459331923714856645280928404198259347205993579213846803666627529909232828722879650374490951581311985882248017934718743944682742282487622451272419143686155769738092352440521581984122740725976684511860250924537999931049740452351974285438729683375867711220177807812280621918795246117514339543091408571088210170010573980132856774272424920513332731618240977627013497573799860486533079269798618961305686700083116612832032852006212842303481886949894366447734991011109426370041918678153\nN: 18107436068843769961592120494384716970785115109411255249546345948609495318598388096607410722799226196024630722689083053376476074858729887106484558379430237472333286381418093839181293825698895861125235085005989001100242472266354948404984880805585806133599679175254980258454991811852588023295429551087087505259481055918651153874312403039948814343657680828818579172724766105080872512340183146177770234401565111928007670988819164086328954605138596051183819569014922240750776080760982732900349444868680946505230852975887754348080529969823222341004758720100799077687160346328480228883962117022614977552611965834106892740279\nphi_N: 18107436068843769961592120494384716970785115109411255249546345948609495318598388096607410722799226196024630722689083053376476074858729887106484558379430237472333286381418093839181293825698895861125235085005989001100242472266354948404984880805585806133599679175254980258454991811852588023295429551087087505259211881071776419056753369694477626905899489032227563034633298774131540832811195538997732185090769133610553176764171454379094498912461830439160755183035087473690870301674200669369623292196413441905049856304683381843183080331417898890517798120267788462525089896252573045317949248770627733246283696022446921596680<\/code><\/pre>\n\n\n\n<p>I wonder if one day I will be able to see the N here being factored into p*q by a quantum computer. If it can be factored, then phi_N can be obtained, and the private key (d, N) can be derived through 65537*d % phi_N = 1. Then the RSA certificate would be doomed.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As we know the RSA certificates Now we got the certificates from let&#8217;s encrypt, so how can be get those values Here is one Python script that print all those details. And here is the output I wonder if one<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[270,169],"tags":[228,260,264],"class_list":["post-2323","post","type-post","status-publish","format-standard","hentry","category-cryptography","category-tech","tag-cryptography","tag-integer-factorization","tag-rsa"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to check the RSA p,q,N,phi_N,e,d - Jianqing&#039;s Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/pjq.me\/?p=2323\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to check the RSA p,q,N,phi_N,e,d - Jianqing&#039;s Blog\" \/>\n<meta property=\"og:description\" content=\"As we know the RSA certificates Now we got the certificates from let&#8217;s encrypt, so how can be get those values Here is one Python script that print all those details. And here is the output I wonder if one\" \/>\n<meta property=\"og:url\" content=\"https:\/\/pjq.me\/?p=2323\" \/>\n<meta property=\"og:site_name\" content=\"Jianqing&#039;s Blog\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-29T10:35:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-11-13T05:25:53+00:00\" \/>\n<meta name=\"author\" content=\"pengjianqing\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"pengjianqing\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/pjq.me\/?p=2323#article\",\"isPartOf\":{\"@id\":\"https:\/\/pjq.me\/?p=2323\"},\"author\":{\"name\":\"pengjianqing\",\"@id\":\"https:\/\/pjq.me\/#\/schema\/person\/0eb1e72d1e69fbbd9b5c0bfd8e2aae60\"},\"headline\":\"How to check the RSA p,q,N,phi_N,e,d\",\"datePublished\":\"2024-11-29T10:35:38+00:00\",\"dateModified\":\"2025-11-13T05:25:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/pjq.me\/?p=2323\"},\"wordCount\":150,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/pjq.me\/#\/schema\/person\/0eb1e72d1e69fbbd9b5c0bfd8e2aae60\"},\"keywords\":[\"Cryptography\",\"Integer Factorization\",\"RSA\"],\"articleSection\":[\"Cryptography\",\"Tech\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/pjq.me\/?p=2323#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/pjq.me\/?p=2323\",\"url\":\"https:\/\/pjq.me\/?p=2323\",\"name\":\"How to check the RSA p,q,N,phi_N,e,d - Jianqing&#039;s Blog\",\"isPartOf\":{\"@id\":\"https:\/\/pjq.me\/#website\"},\"datePublished\":\"2024-11-29T10:35:38+00:00\",\"dateModified\":\"2025-11-13T05:25:53+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/pjq.me\/?p=2323#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/pjq.me\/?p=2323\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/pjq.me\/?p=2323#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/pjq.me\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to check the RSA p,q,N,phi_N,e,d\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/pjq.me\/#website\",\"url\":\"https:\/\/pjq.me\/\",\"name\":\"Jianqing&#039;s Blog\",\"description\":\"Thoughts and Future\",\"publisher\":{\"@id\":\"https:\/\/pjq.me\/#\/schema\/person\/0eb1e72d1e69fbbd9b5c0bfd8e2aae60\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/pjq.me\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/pjq.me\/#\/schema\/person\/0eb1e72d1e69fbbd9b5c0bfd8e2aae60\",\"name\":\"pengjianqing\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/pjq.me\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/pjq.me\/wp-content\/uploads\/2021\/12\/Screen-Shot-2021-12-02-at-6.10.58-PM.png\",\"contentUrl\":\"https:\/\/pjq.me\/wp-content\/uploads\/2021\/12\/Screen-Shot-2021-12-02-at-6.10.58-PM.png\",\"width\":460,\"height\":752,\"caption\":\"pengjianqing\"},\"logo\":{\"@id\":\"https:\/\/pjq.me\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/pjq.me\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to check the RSA p,q,N,phi_N,e,d - Jianqing&#039;s Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/pjq.me\/?p=2323","og_locale":"en_US","og_type":"article","og_title":"How to check the RSA p,q,N,phi_N,e,d - Jianqing&#039;s Blog","og_description":"As we know the RSA certificates Now we got the certificates from let&#8217;s encrypt, so how can be get those values Here is one Python script that print all those details. And here is the output I wonder if one","og_url":"https:\/\/pjq.me\/?p=2323","og_site_name":"Jianqing&#039;s Blog","article_published_time":"2024-11-29T10:35:38+00:00","article_modified_time":"2025-11-13T05:25:53+00:00","author":"pengjianqing","twitter_card":"summary_large_image","twitter_misc":{"Written by":"pengjianqing","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/pjq.me\/?p=2323#article","isPartOf":{"@id":"https:\/\/pjq.me\/?p=2323"},"author":{"name":"pengjianqing","@id":"https:\/\/pjq.me\/#\/schema\/person\/0eb1e72d1e69fbbd9b5c0bfd8e2aae60"},"headline":"How to check the RSA p,q,N,phi_N,e,d","datePublished":"2024-11-29T10:35:38+00:00","dateModified":"2025-11-13T05:25:53+00:00","mainEntityOfPage":{"@id":"https:\/\/pjq.me\/?p=2323"},"wordCount":150,"commentCount":0,"publisher":{"@id":"https:\/\/pjq.me\/#\/schema\/person\/0eb1e72d1e69fbbd9b5c0bfd8e2aae60"},"keywords":["Cryptography","Integer Factorization","RSA"],"articleSection":["Cryptography","Tech"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/pjq.me\/?p=2323#respond"]}]},{"@type":"WebPage","@id":"https:\/\/pjq.me\/?p=2323","url":"https:\/\/pjq.me\/?p=2323","name":"How to check the RSA p,q,N,phi_N,e,d - Jianqing&#039;s Blog","isPartOf":{"@id":"https:\/\/pjq.me\/#website"},"datePublished":"2024-11-29T10:35:38+00:00","dateModified":"2025-11-13T05:25:53+00:00","breadcrumb":{"@id":"https:\/\/pjq.me\/?p=2323#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/pjq.me\/?p=2323"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/pjq.me\/?p=2323#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/pjq.me\/"},{"@type":"ListItem","position":2,"name":"How to check the RSA p,q,N,phi_N,e,d"}]},{"@type":"WebSite","@id":"https:\/\/pjq.me\/#website","url":"https:\/\/pjq.me\/","name":"Jianqing&#039;s Blog","description":"Thoughts and Future","publisher":{"@id":"https:\/\/pjq.me\/#\/schema\/person\/0eb1e72d1e69fbbd9b5c0bfd8e2aae60"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/pjq.me\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/pjq.me\/#\/schema\/person\/0eb1e72d1e69fbbd9b5c0bfd8e2aae60","name":"pengjianqing","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/pjq.me\/#\/schema\/person\/image\/","url":"https:\/\/pjq.me\/wp-content\/uploads\/2021\/12\/Screen-Shot-2021-12-02-at-6.10.58-PM.png","contentUrl":"https:\/\/pjq.me\/wp-content\/uploads\/2021\/12\/Screen-Shot-2021-12-02-at-6.10.58-PM.png","width":460,"height":752,"caption":"pengjianqing"},"logo":{"@id":"https:\/\/pjq.me\/#\/schema\/person\/image\/"},"url":"https:\/\/pjq.me\/?author=1"}]}},"views":1682,"_links":{"self":[{"href":"https:\/\/pjq.me\/index.php?rest_route=\/wp\/v2\/posts\/2323","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pjq.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pjq.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pjq.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pjq.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2323"}],"version-history":[{"count":5,"href":"https:\/\/pjq.me\/index.php?rest_route=\/wp\/v2\/posts\/2323\/revisions"}],"predecessor-version":[{"id":2330,"href":"https:\/\/pjq.me\/index.php?rest_route=\/wp\/v2\/posts\/2323\/revisions\/2330"}],"wp:attachment":[{"href":"https:\/\/pjq.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pjq.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2323"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pjq.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}