0

I'm going to generate a key pair on this tutorial but I cannot open the generated private key in TextEdit.

I already enabled "Allow all applications to access this item" from "Get Info" pane but I still cannot open the file. There is also no /etc/certificates directory on my system, unlike the suggested comment there.

I just want to copy the content of the key and don't need to open it in TextEdit. But how can I check the content of it?

I use macOS 12.12.1.

enter image description here

2 Answers 2

2

Note: This answer was tested using macOS High Sierra 10.13.6 and macOS Monterey 12.1. The images below are from Monterey.

Picking up from where the tutorial left off, I have the public and private keys in the Keychain Access application, as shown below.

keychain access

From the Keychain Access application, you can export the public and private keys to files. Here, I saved the public key as nctest.com in my Documents folder, which created the text file ~/Documents/nctest.com.pem. I also saved the private key as nctest.com in my in my Documents folder, which created the text file ~/Documents/nctest.com.p12. When prompted, I chose to not to enter a password. In other words, when the popup below appeared, I did not enter any text in the "Password:" or "Verify:" text boxes and just selected the OK button. For the purposes of additional security, you may wish to enter a stronger password.

password

The public key can be displayed by entering the following command in a Terminal application window.

cat ~/Documents/nctest.com.pem

Sample output is given below.

-----BEGIN RSA PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvF52ctPK2AJctLlBoDn9
tisRPPUqFUuBsyqUezm8QbmUNhnAfNN+skteXU9Mud042f+5NLDnsCg9PuiMAXqJ
YEd7PU/iYU7fYCnjNAJriyjSQ8ClV9KYN/4KSeSvc9NBizAbYFeJqcQ4HDPIg0bA
Chxcdy02T1W47TtizIh6oGxM7kFqBCJ1wrZKz2nAEggAZFp2SH3ZvlGkfsVOvfKd
wrOezYI3D1cx97BVGEj+U9Ciaz5e63cScqgTIoEAsdcCNT6f15odMmzvqN58LfSS
gIokL+2IjcEeZqYgj1TE9LA/7D0hLrnU5sKr6Cs1SJQH8X3+WpS0GSOlBOyx16+H
8wIDAQAB
-----END RSA PUBLIC KEY-----

The private key can be displayed by entering the following command in a Terminal application window.

Note: If you entered some text for a password, then this password needs to be included immediately after the colon (:) character. Or, you can be prompted for the password by omitting the -passin pass: option and argument.

openssl pkcs12 -nodes -passin pass: -in ~/Documents/nctest.com.p12

Sample output is given below.

MAC verified OK
Bag Attributes
    friendlyName: nctest.com
    localKeyID: F4 47 72 98 49 70 3B E6 80 C6 2A A1 27 BB 8B F4 0B BC 3F E9 
Key Attributes: <No Attributes>
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC8XnZy08rYAly0
uUGgOf22KxE89SoVS4GzKpR7ObxBuZQ2GcB8036yS15dT0y53TjZ/7k0sOewKD0+
6IwBeolgR3s9T+JhTt9gKeM0AmuLKNJDwKVX0pg3/gpJ5K9z00GLMBtgV4mpxDgc
M8iDRsAKHFx3LTZPVbjtO2LMiHqgbEzuQWoEInXCtkrPacASCABkWnZIfdm+UaR+
xU698p3Cs57NgjcPVzH3sFUYSP5T0KJrPl7rdxJyqBMigQCx1wI1Pp/Xmh0ybO+o
3nwt9JKAiiQv7YiNwR5mpiCPVMT0sD/sPSEuudTmwqvoKzVIlAfxff5alLQZI6UE
7LHXr4fzAgMBAAECggEAV3aNDRgmEVJXdVqnjBwhH9qzcFhtp+GdYXGd6/GM5f+j
P9OJOuyA4Yx5Tl4pxAtiAGbqufqCOZsVhQY5K96Xtuq54GgdNw2GToJkiputD7pu
lyL2IucX4rfEUzcp+F/ZCSXXME61DuybGQ06RyostQUiMfv+QawN56kxYMLmHWIf
LkzQ3XmasCayHFR5zdJvYj1ma1YirkgagYq+54iinCAKNZoJxfFZOdOg8M/wE4rS
odEz9HEwhRImzjG3tac4Pc/7NfNscQQAgVIqd7j5hQ+zA+t69rfLdJHp064fXtmI
BA9+rsN00E7o0UBIg7cQNuFGij7yu7YYxsk4ZmTLoQKBgQDxB6ctUpR+3oEwDLcK
XhgEGaDRVDJBw+a7OOgE4qrqL8OnBcyDh3/bklcOITu6MhvIg7e7STioVkLwrW8s
A6KhDCdKYCxLt6IlyMZlYo7se8PV/jM9FNm0FvL5iXkNY7R1xel6NCUWqxGROnkx
uyRVZOCWzHqTwkAVgXiNDSIkuQKBgQDIEYHuZu3z2RuYSXcleOC/kB+vexi2lIyo
E7sPyhaaexLG7AATRJSHySIzbUtHB6/JBeW41j3m0cBhXWzodKufbEpSxmcNFrXY
SKATE7e/Guxub2OV6BjqGRKd8u4U5/JtaTZWAykuZNls65H/NiYv+96Ox4PVLKIS
V1ZV9WWUCwKBgCj+/z1jPWSy3dBZaUy3ImiYH1Vbd8zd0EHp9PTXxPBePW4MO3Pn
uSSUqH/7wRfza+xYEwkk9CEVwv8C0NTwrVmtIoWxA/fA/TBmDPCzqdGpX27ndLmf
8UODX8J30oIngktB5WtmsSRA5pUIGBMQXKa1qMmdb//v20yNH/8Fy9fpAoGAd1RB
7CEGUkgvNlCzOO11F6ztySuhnNzTXDiQfSVq/+7iTzVaAiQId0jXFldc69vA1CSp
VOqr9y0qEqi3mZpk9uyPE/n0YxElmwAOQfKjyN9VH7Veb34ExjP4L69Co8OIjAuR
9hFikaJjMJz88nyooDwZDY4gqpg5frkK7LA2SusCgYEA72DWlN+OmP/IWJyG0xb4
sj/wWEgejI1QqLPVdyBFQQApmwhRUa7V6YmkmzClh7Hklk3o+G1fx+fi70CWB9Nw
XJZsDFJfLDdD5SIrQumiPiowrUH5pdHJJj2C+cPAKi+cxSCd76OmxtEX3wWT4rNV
dGPsLLntAJEOwhzyGzNb4c4=
-----END PRIVATE KEY-----

You can verify the public key was generated from the private key by entering the command below in a Terminal application window.

openssl pkcs12 -nodes -passin pass: -in ~/Documents/nctest.com.p12 | openssl rsa -pubout

Sample output is given below.

MAC verified OK
writing RSA key
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvF52ctPK2AJctLlBoDn9
tisRPPUqFUuBsyqUezm8QbmUNhnAfNN+skteXU9Mud042f+5NLDnsCg9PuiMAXqJ
YEd7PU/iYU7fYCnjNAJriyjSQ8ClV9KYN/4KSeSvc9NBizAbYFeJqcQ4HDPIg0bA
Chxcdy02T1W47TtizIh6oGxM7kFqBCJ1wrZKz2nAEggAZFp2SH3ZvlGkfsVOvfKd
wrOezYI3D1cx97BVGEj+U9Ciaz5e63cScqgTIoEAsdcCNT6f15odMmzvqN58LfSS
gIokL+2IjcEeZqYgj1TE9LA/7D0hLrnU5sKr6Cs1SJQH8X3+WpS0GSOlBOyx16+H
8wIDAQAB
-----END PUBLIC KEY-----

References:

2
  • Note that if you export the private key without a password to protect it, you need to be very careful about keeping the export file itself secret; if anyone gets a copy of it, your certificate is no longer secure. Mar 8 at 20:48
  • @GordonDavisson: I should point out that not entering a password is a password, albeit a weak one. In other words, I do not think the Keychain Access application will export the private key to a P12 file without encryption. Mar 8 at 22:09
1

The tutorial you've linked writes about opening the certificate signing request in TextEdit, not the private key. They want you to send the CSR to a form on their site.

You cannot access private keys from the keychain directly. If you need to access the private key, for example because you need to copy the identity (certificate + private key) to another machine, you need to export it using PKCS#12: Select the certificate and its private key in Keychain Access, then use the menu File > Export Items …. You are required to password-protect the PKCS#12 file. How to import the PKCS#12 on the target machine depends on what kind of OS it's running and is beyond the scope of this question.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .