Skip to content

Commit 434faa4

Browse files
crypto/x509: change docs to clarify the meaning of PEM encryption
The existing documentation does not mention the exact meaning of "PEM encryption". So add a note to clarify that it is referring to RFC 1423 and that the functions are not meant to support any newer standard like PKCS #8. Updates #41949
1 parent c8f6135 commit 434faa4

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/crypto/x509/pem_decrypt.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ func (c rfc1423Algo) deriveKey(password, salt []byte) []byte {
9696
}
9797

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

0 commit comments

Comments
 (0)