Class PemUtils

java.lang.Object
software.amazon.awssdk.crt.utils.PemUtils

public class PemUtils extends Object
Utility Class used for Cleaning Up and Sanity Checking PEM formatted Strings for Validity.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    Cleanup Function that removes most formatting and copy/paste mistakes from PEM formatted Strings.
    static String
    Removes characters that are not valid in PEM format (non-base64 chars).
    static boolean
    safeSanityCheck(String pem, int maxChainLength, String expectedPemTypeSubString)
    Returns false if there is a problem with a PEM instead of throwing an Exception.
    static void
    sanityCheck(String pem, int maxChainLength, String expectedPemTypeSubString)
    Performs various sanity checks on a PEM Formatted String, and should be tolerant of common minor mistakes in formatting.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • removeInvalidPemChars

      public static String removeInvalidPemChars(String pem)
      Removes characters that are not valid in PEM format (non-base64 chars). No other cleanup is done.
      Parameters:
      pem - The input "dirty" PEM
      Returns:
      The output "clean" PEM
    • cleanUpPem

      public static String cleanUpPem(String pem)
      Cleanup Function that removes most formatting and copy/paste mistakes from PEM formatted Strings.
      Parameters:
      pem - The input "dirty" PEM
      Returns:
      The output "clean" PEM
    • sanityCheck

      public static void sanityCheck(String pem, int maxChainLength, String expectedPemTypeSubString)
      Performs various sanity checks on a PEM Formatted String, and should be tolerant of common minor mistakes in formatting.
      Parameters:
      pem - The PEM or PEM Chain to validate.
      maxChainLength - The max number of PEM encoded objects in the String.
      expectedPemTypeSubString - A Substring that is expected to be present in the PEM Type.
      Throws:
      IllegalArgumentException - if there is a problem with the PEM formatted String.
    • safeSanityCheck

      public static boolean safeSanityCheck(String pem, int maxChainLength, String expectedPemTypeSubString)
      Returns false if there is a problem with a PEM instead of throwing an Exception.
      Parameters:
      pem - The PEM to sanity check.
      maxChainLength - The Max number of PEM Objects in the PEM String
      expectedPemTypeSubString - A Substring that is expected to be present in the PEM Type.
      Returns:
      True if the PEM passes all sanity Checks, false otherwise.