Class Utils


  • public class Utils
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and TypeFieldDescription
      static java.lang.StringALGORITHM 
      static java.lang.StringCURVE 
    • Constructor Summary

      Constructors 
      ConstructorDescription
      Utils() 
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and TypeMethodDescription
      static intcombinedLength​(byte[]... arrays)
      Compute combined array length
      static byte[]concat​(byte[]... arrays)
      Utility to concat byte arrays
      static byte[]encode​(org.bouncycastle.jce.interfaces.ECPrivateKey privateKey) 
      static byte[]encode​(org.bouncycastle.jce.interfaces.ECPublicKey publicKey)
      Get the uncompressed encoding of the public key point.
      static java.security.PrivateKeyloadPrivateKey​(byte[] decodedPrivateKey)
      Load the private key from a byte array
      static java.security.PrivateKeyloadPrivateKey​(java.lang.String encodedPrivateKey)
      Load the private key from a URL-safe base64 encoded string
      static java.security.PublicKeyloadPublicKey​(byte[] decodedPublicKey)
      Load the public key from a byte array.
      static java.security.PublicKeyloadPublicKey​(java.lang.String encodedPublicKey)
      Load the public key from a URL-safe base64 encoded string.
      static org.bouncycastle.jce.interfaces.ECPublicKeyloadPublicKey​(org.bouncycastle.jce.interfaces.ECPrivateKey privateKey)
      Load a public key from the private key.
      static byte[]toByteArray​(int integer, int size)
      Create a byte array of the given length from the given integer.
      static booleanverifyKeyPair​(java.security.PrivateKey privateKey, java.security.PublicKey publicKey)
      Verify that the private key belongs to the public key.
      • Methods inherited from class java.lang.Object

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

      • Utils

        public Utils()
    • Method Detail

      • encode

        public static byte[] encode​(org.bouncycastle.jce.interfaces.ECPublicKey publicKey)
        Get the uncompressed encoding of the public key point. The resulting array should be 65 bytes length and start with 0x04 followed by the x and y coordinates (32 bytes each).
        Parameters:
        publicKey -
        Returns:
      • encode

        public static byte[] encode​(org.bouncycastle.jce.interfaces.ECPrivateKey privateKey)
      • loadPublicKey

        public static java.security.PublicKey loadPublicKey​(java.lang.String encodedPublicKey)
                                                     throws java.security.NoSuchProviderException,
                                                            java.security.NoSuchAlgorithmException,
                                                            java.security.spec.InvalidKeySpecException
        Load the public key from a URL-safe base64 encoded string. Takes into account the different encodings, including point compression.
        Parameters:
        encodedPublicKey -
        Throws:
        java.security.NoSuchProviderException
        java.security.NoSuchAlgorithmException
        java.security.spec.InvalidKeySpecException
      • loadPublicKey

        public static java.security.PublicKey loadPublicKey​(byte[] decodedPublicKey)
                                                     throws java.security.NoSuchProviderException,
                                                            java.security.NoSuchAlgorithmException,
                                                            java.security.spec.InvalidKeySpecException
        Load the public key from a byte array.
        Parameters:
        decodedPublicKey -
        Throws:
        java.security.NoSuchProviderException
        java.security.NoSuchAlgorithmException
        java.security.spec.InvalidKeySpecException
      • loadPrivateKey

        public static java.security.PrivateKey loadPrivateKey​(java.lang.String encodedPrivateKey)
                                                       throws java.security.NoSuchProviderException,
                                                              java.security.NoSuchAlgorithmException,
                                                              java.security.spec.InvalidKeySpecException
        Load the private key from a URL-safe base64 encoded string
        Parameters:
        encodedPrivateKey -
        Returns:
        Throws:
        java.security.NoSuchProviderException
        java.security.NoSuchAlgorithmException
        java.security.spec.InvalidKeySpecException
      • loadPrivateKey

        public static java.security.PrivateKey loadPrivateKey​(byte[] decodedPrivateKey)
                                                       throws java.security.NoSuchProviderException,
                                                              java.security.NoSuchAlgorithmException,
                                                              java.security.spec.InvalidKeySpecException
        Load the private key from a byte array
        Parameters:
        decodedPrivateKey -
        Returns:
        Throws:
        java.security.NoSuchProviderException
        java.security.NoSuchAlgorithmException
        java.security.spec.InvalidKeySpecException
      • loadPublicKey

        public static org.bouncycastle.jce.interfaces.ECPublicKey loadPublicKey​(org.bouncycastle.jce.interfaces.ECPrivateKey privateKey)
                                                                         throws java.security.NoSuchProviderException,
                                                                                java.security.NoSuchAlgorithmException,
                                                                                java.security.spec.InvalidKeySpecException
        Load a public key from the private key.
        Parameters:
        privateKey -
        Returns:
        Throws:
        java.security.NoSuchProviderException
        java.security.NoSuchAlgorithmException
        java.security.spec.InvalidKeySpecException
      • verifyKeyPair

        public static boolean verifyKeyPair​(java.security.PrivateKey privateKey,
                                            java.security.PublicKey publicKey)
        Verify that the private key belongs to the public key.
        Parameters:
        privateKey -
        publicKey -
        Returns:
      • concat

        public static byte[] concat​(byte[]... arrays)
        Utility to concat byte arrays
      • combinedLength

        public static int combinedLength​(byte[]... arrays)
        Compute combined array length
      • toByteArray

        public static byte[] toByteArray​(int integer,
                                         int size)
        Create a byte array of the given length from the given integer.
        Parameters:
        integer -
        size -
        Returns: