Class Keys


  • public class Keys
    extends java.lang.Object
    For internal use. Key related utility functions.
    • Constructor Summary

      Constructors 
      Constructor Description
      Keys()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.security.PublicKey constructTufPublicKey​(byte[] contents, java.lang.String scheme)
      Valid values for scheme are: ed25519 ecdsa-sha2-nistp256
      static java.security.PublicKey parsePkcs1RsaPublicKey​(byte[] contents)  
      static java.security.PublicKey parsePkixPublicKey​(byte[] contents, java.lang.String algorithm)
      Takes a PKIX DER formatted public key in bytes and constructs a PublicKey with it.
      static java.security.PublicKey parsePublicKey​(byte[] keyBytes)
      Takes a PEM formatted public key in bytes and constructs a PublicKey with it.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Keys

        public Keys()
    • Method Detail

      • parsePublicKey

        public static java.security.PublicKey parsePublicKey​(byte[] keyBytes)
                                                      throws java.security.spec.InvalidKeySpecException,
                                                             java.io.IOException,
                                                             java.security.NoSuchAlgorithmException
        Takes a PEM formatted public key in bytes and constructs a PublicKey with it.

        This method supports the follow public key algorithms: RSA, EdDSA, EC.

        Throws:
        java.security.spec.InvalidKeySpecException - if the PEM does not contain just one public key.
        java.security.NoSuchAlgorithmException - if the public key is using an unsupported algorithm.
        java.io.IOException
      • parsePkixPublicKey

        public static java.security.PublicKey parsePkixPublicKey​(byte[] contents,
                                                                 java.lang.String algorithm)
                                                          throws java.security.NoSuchAlgorithmException,
                                                                 java.security.spec.InvalidKeySpecException
        Takes a PKIX DER formatted public key in bytes and constructs a PublicKey with it.

        This method is known to work with keys algorithms: RSA, EdDSA, EC.

        Parameters:
        contents - the public key bytes
        algorithm - the key algorithm
        Returns:
        a PublicKey object
        Throws:
        java.security.NoSuchAlgorithmException - if we don't support the scheme provided
        java.security.spec.InvalidKeySpecException - if the public key material is invalid
      • parsePkcs1RsaPublicKey

        public static java.security.PublicKey parsePkcs1RsaPublicKey​(byte[] contents)
                                                              throws java.security.NoSuchAlgorithmException,
                                                                     java.security.spec.InvalidKeySpecException
        Throws:
        java.security.NoSuchAlgorithmException
        java.security.spec.InvalidKeySpecException
      • constructTufPublicKey

        public static java.security.PublicKey constructTufPublicKey​(byte[] contents,
                                                                    java.lang.String scheme)
                                                             throws java.security.NoSuchAlgorithmException,
                                                                    java.security.spec.InvalidKeySpecException
        Valid values for scheme are:
        1. ed25519
        2. ecdsa-sha2-nistp256
        Parameters:
        contents - keyBytes
        scheme - signing scheme
        Returns:
        java {link PublicKey}
        Throws:
        java.security.NoSuchAlgorithmException - if we don't support the scheme provided
        java.security.spec.InvalidKeySpecException - if the public key material is invalid
        See Also:
        spec