Standard library / crypto/x509

crypto/x509.IsEncryptedPEMBlock()

Legacy RFC 1423 PEM encryption is unauthenticated and susceptible to padding-oracle attacks. Do not use for new key storage. Checks the legacy DEK-Info header; does not validate or decrypt the contents. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func IsEncryptedPEMBlock(b *pem.Block) bool

Parameters & Attributes

NameTypeDescription
b*pem.BlockBinary OID content or PEM block, according to signature.

Return Value

bool

Result as described above; check any returned error before use.

Working Example

Example Snippetgo
package main
import (  "crypto/rand"  "crypto/x509"  "fmt")
func main() {  // Historical interoperability demonstration only. Prefer modern protocols for new designs.  b := must(x509.EncryptPEMBlock(rand.Reader, "DEMO", []byte("Go"), []byte("test-only"), x509.PEMCipherAES256))  fmt.Println(x509.IsEncryptedPEMBlock(b))}
func must[T any](v T, e error) T {  if e != nil {    panic(e)  }  return v}func check(e error) {  if e != nil {    panic(e)  }}
Go Reference