Skip to content

crypto/x509: change docs to clarify the meaning of PEM encryption #42039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/crypto/x509/pem_decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ func (c rfc1423Algo) deriveKey(password, salt []byte) []byte {
}

// IsEncryptedPEMBlock returns if the PEM block is password encrypted.
// Note: PEM encryption in this package is referring specifically to
// https://tools.ietf.org/html/rfc1423 . This function is not meant to
// detect newer standards like PKCS #8 https://tools.ietf.org/html/rfc5208#section-6
func IsEncryptedPEMBlock(b *pem.Block) bool {
_, ok := b.Headers["DEK-Info"]
return ok
Expand All @@ -112,6 +115,9 @@ var IncorrectPasswordError = errors.New("x509: decryption password incorrect")
// in the encrypted-PEM format, it's not always possible to detect an incorrect
// password. In these cases no error will be returned but the decrypted DER
// bytes will be random noise.
// Note: PEM encryption in this package is referring specifically to
// https://tools.ietf.org/html/rfc1423 . This function is not meant to
// decrpyt newer standards like PKCS #8 https://tools.ietf.org/html/rfc5208#section-6
func DecryptPEMBlock(b *pem.Block, password []byte) ([]byte, error) {
dek, ok := b.Headers["DEK-Info"]
if !ok {
Expand Down Expand Up @@ -180,6 +186,8 @@ func DecryptPEMBlock(b *pem.Block, password []byte) ([]byte, error) {
// EncryptPEMBlock returns a PEM block of the specified type holding the
// given DER-encoded data encrypted with the specified algorithm and
// password.
// Note: PEM encryption in this package is referring specifically to
// https://tools.ietf.org/html/rfc1423
func EncryptPEMBlock(rand io.Reader, blockType string, data, password []byte, alg PEMCipher) (*pem.Block, error) {
ciph := cipherByKey(alg)
if ciph == nil {
Expand Down