Function pemtob64

  • get Base64 string from PEM format data

    Parameters

    • pem: string

      PEM formatted string

    • Optional sHead: string

      PEM header string without BEGIN/END

    Returns string

    base64 string in the first PEM

    Description

    This static method gets a Base64 string of contents from PEM format data. As for the "pem", some garbled text before and after the PEM header also be acceptable. When two or more PEMs are included, the first one will be returned.

    Example

    pemtob64("-----BEGIN CERTIFICATE...", "CERTIFICATE") -> "MIIBvTCC..."
    pemtob64("-----BEGIN CERTIFICATE...", "CERTIFICATE") -> "MIIBvTCC..."
    pemtob64("-----BEGIN CERTIFICATE...") -> "MIIBvTCC..."
    pem2 = `
    junk-text
    -----BEGIN FOO----
    YWFh
    -----BEGIN FOO----
    junk-text
    -----BEGIN BOO BOO----
    enp6
    -----BEGIN BOO BOO----
    junk-text
    `
    pemtob64(pem2) -> "YWFh"