Class PrivateKeySources


  • public class PrivateKeySources
    extends Object

    Static factory methods used to create instances of PrivateKeySource.

    Examples:

    The following is an example of commands that uses OpenSSL to generate a file that can be handled with PrivateKeySources.

     openssl ecparam -genkey -name prime256v1 -noout -out my-private.pem
     openssl pkcs8 -in my-private.pem -topk8 -nocrypt -out my-private_pkcs8.pem
     

    If you want to generate in DER format, you can also do as follows.

     openssl pkcs8 -in my-private.pem -topk8 -nocrypt -outform der -out my-private_pkcs8.der
     

    The examples of using these files to create PrivateKeySources are as follows.

     Path pemPath = new File("my-private_pkcs8.pem").toPath();
     Path derPath = new File("my-private_pkcs8.der").toPath();
    
     PrivateKeySource pemSource = PrivateKeySources.ofPEMFile(pemPath);
     PrivateKeySource derSource = PrivateKeySources.ofDERFile(derPath);
    
     byte[] pemBytes = Files.readAllBytes(pemPath);
     String pemText = new String(pemBytes, StandardCharsets.UTF_8);
     PrivateKeySource pemSource2 = PrivateKeySources.ofPEMText(pemText);
    
     byte[] derBytes = Files.readAllBytes(derPath);
     PrivateKeySource derSource2 = PrivateKeySources.ofPKCS8Bytes(derBytes);
    
     
    Thread Safety:

    Instances obtained through a factory method of this class are thread-safe.

    Author:
    Tomoki Sato
    See Also:
    PrivateKeySource, PublicKeySource, PublicKeySources