Class SecurityUtils

java.lang.Object
io.skodjob.testframe.utils.SecurityUtils

public class SecurityUtils extends Object
Utils for manipulating with certs
  • Method Details

    • exportToPemFiles

      public static CertAndKeyFiles exportToPemFiles(CertAndKey... certs)
      Export in-memory cert and key into pem files
      Parameters:
      certs - im memory certs
      Returns:
      exported files
    • convertPrivateKeyToPKCS8File

      public static File convertPrivateKeyToPKCS8File(PrivateKey privatekey) throws NoSuchAlgorithmException, InvalidKeySpecException, IOException
      Converts private key into PKCS8File
      Parameters:
      privatekey - private key
      Returns:
      exported file on disk
      Throws:
      NoSuchAlgorithmException - bad algorithm
      InvalidKeySpecException - bad key
      IOException - io exception
    • exportCaDataToFile

      public static File exportCaDataToFile(String caData, String prefix, String suffix)
      This method exports Certificate Authority (CA) data to a temporary file for cases in which mentioned data is necessary in form of file - for use in applications like OpenSSL. The primary purpose is to save CA files, such as certificates and private keys (e.g., ca.key and ca.cert), into temporary files. These files are essential when you need to provide CA data to other applications, such as OpenSSL, for signing user Certificate Signing Requests (CSRs).
      Parameters:
      caData - The Certificate Authority data to be saved to the temporary file.
      prefix - The prefix for the temporary file's name.
      suffix - The suffix for the temporary file's name.
      Returns:
      A File object representing the temporary file containing the CA data.
      Throws:
      RuntimeException - If an IOException occurs while creating a file or writing into the temporary file given the critical role these operations play in ensuring proper functionality.
    • containsAllDN

      public static boolean containsAllDN(String principal1, String principal2)
      Check if principal1 contains all dns of principal2 in dn
      Parameters:
      principal1 - principal
      principal2 - principal
      Returns:
      true of principal 1 contains all dn of principal 2