Class KeyUtils


  • public final class KeyUtils
    extends Object
    • Field Detail

      • RSA_ECB_OAEPWITH_SHA1_AND_MGF1_PADDING

        public static final String RSA_ECB_OAEPWITH_SHA1_AND_MGF1_PADDING
        See Also:
        Constant Field Values
    • Method Detail

      • getKeyLength

        public static int getKeyLength​(String algorithm)
                                throws WSSecurityException
        Returns the length of the key in # of bytes. For the HMAC algorithms it guesses a default value that can be used based on the algorithm.
        Parameters:
        algorithm - the URI of the algorithm. See http://www.w3.org/TR/xmlenc-core1/
        Returns:
        the key length
        Throws:
        WSSecurityException
      • prepareSecretKey

        public static SecretKey prepareSecretKey​(String algorithm,
                                                 byte[] rawKey)
        Convert the raw key bytes into a SecretKey object of type algorithm.
      • getCipherInstance

        public static Cipher getCipherInstance​(String cipherAlgo)
                                        throws WSSecurityException
        Translate the "cipherAlgo" URI to a JCE ID, and return a javax.crypto.Cipher instance of this type.
        Parameters:
        cipherAlgo - The cipher in it's WSS URI form, ref. https://www.w3.org/TR/xmlenc-core1/#sec-Algorithms
        Throws:
        WSSecurityException
      • getCipherInstance

        public static Cipher getCipherInstance​(String cipherAlgo,
                                               String provider)
                                        throws WSSecurityException
        Translate the "cipherAlgo" URI to a JCE ID, and request a javax.crypto.Cipher instance of this type from the given provider.
        Parameters:
        cipherAlgo - The cipher in it's WSS URI form, ref. https://www.w3.org/TR/xmlenc-core1/#sec-Algorithms
        provider - The provider which shall instantiate the cipher.
        Throws:
        WSSecurityException
      • generateDigest

        public static byte[] generateDigest​(byte[] inputBytes)
                                     throws WSSecurityException
        Generate a (SHA1) digest of the input bytes. The MessageDigest instance that backs this method is cached for efficiency.
        Parameters:
        inputBytes - the bytes to digest
        Returns:
        the digest of the input bytes
        Throws:
        WSSecurityException