org.apache.cxf.common.util.crypto

## Class CryptoUtils

- java.lang.Object
- - org.apache.cxf.common.util.crypto.CryptoUtils

-     public final class CryptoUtils
      extends Object

  Encryption helpers

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static SecretKey` | `createSecretKeySpec(byte[] bytes, String algo)`
    `static SecretKey` | `createSecretKeySpec(String encodedBytes, String algo)`
    `static Certificate` | `decodeCertificate(String encodedCert)`
    `static SecretKey` | `decodeSecretKey(String encodedSecretKey)`
    `static SecretKey` | `decodeSecretKey(String encodedSecretKey, String secretKeyAlgo)`
    `static byte[]` | `decodeSequence(String encodedSequence)`
    `static byte[]` | `decryptBytes(byte[] bytes, Key secretKey)`
    `static byte[]` | `decryptBytes(byte[] bytes, Key secretKey, KeyProperties keyProps)`
    `static SecretKey` | `decryptSecretKey(String encodedEncryptedSecretKey, PrivateKey privateKey)`
    `static SecretKey` | `decryptSecretKey(String encodedEncryptedSecretKey, String secretKeyAlgo, KeyProperties props, PrivateKey privateKey)`
    `static SecretKey` | `decryptSecretKey(String encodedEncryptedSecretKey, String secretKeyAlgo, PrivateKey privateKey)`
    `static String` | `decryptSequence(String encodedData, Key secretKey)`
    `static String` | `decryptSequence(String encodedData, Key secretKey, KeyProperties props)`
    `static String` | `decryptSequence(String encodedToken, String encodedSecretKey)`
    `static String` | `decryptSequence(String encodedData, String encodedSecretKey, KeyProperties props)`
    `static String` | `encodeBytes(byte[] bytes)`
    `static String` | `encodeCertificate(Certificate cert)`
    `static String` | `encodeSecretKey(SecretKey key)`
    `static byte[]` | `encryptBytes(byte[] bytes, Key secretKey)`
    `static byte[]` | `encryptBytes(byte[] bytes, Key secretKey, KeyProperties keyProps)`
    `static String` | `encryptSecretKey(SecretKey secretKey, PublicKey publicKey)`
    `static String` | `encryptSecretKey(SecretKey secretKey, PublicKey publicKey, KeyProperties props)`
    `static String` | `encryptSequence(String sequence, Key secretKey)`
    `static String` | `encryptSequence(String sequence, Key secretKey, KeyProperties keyProps)`
    `static KeyPair` | `generateECKeyPair(String curve)`
    `static byte[]` | `generateSecureRandomBytes(int size)`
    `static AlgorithmParameterSpec` | `getContentEncryptionCipherSpec(int authTagLength, byte[] iv)`
    `static ECPrivateKey` | `getECPrivateKey(String curve, byte[] privateKey)`
    `static ECPrivateKey` | `getECPrivateKey(String curve, String encodedPrivateKey)`
    `static ECPublicKey` | `getECPublicKey(String curve, byte[] xPoint, byte[] yPoint)`
    `static ECPublicKey` | `getECPublicKey(String curve, String encodedXPoint, String encodedYPoint)`
    `static AlgorithmParameterSpec` | `getGCMParameterSpec(int authTagLength, byte[] iv)`
    `static RSAPrivateKey` | `getRSAPrivateKey(byte[] modulusBytes, byte[] privateExponentBytes)`
    `static RSAPrivateKey` | `getRSAPrivateKey(byte[] modulusBytes, byte[] publicExponentBytes, byte[] privateExponentBytes, byte[] primePBytes, byte[] primeQBytes, byte[] primeExpPBytes, byte[] primeExpQBytes, byte[] crtCoefficientBytes)`
    `static RSAPrivateKey` | `getRSAPrivateKey(String encodedModulus, String encodedPrivateExponent)`
    `static RSAPrivateKey` | `getRSAPrivateKey(String encodedModulus, String encodedPublicExponent, String encodedPrivateExponent, String encodedPrimeP, String encodedPrimeQ, String encodedPrimeExpP, String encodedPrimeExpQ, String encodedCrtCoefficient)`
    `static RSAPublicKey` | `getRSAPublicKey(byte[] modulusBytes, byte[] publicExponentBytes)`
    `static RSAPublicKey` | `getRSAPublicKey(KeyFactory factory, byte[] modulusBytes, byte[] publicExponentBytes)`
    `static RSAPublicKey` | `getRSAPublicKey(String encodedModulus, String encodedPublicExponent)`
    `static SecretKey` | `getSecretKey(KeyProperties props)`
    `static SecretKey` | `getSecretKey(String symEncAlgo)`
    `static SecretKey` | `getSecretKey(String symEncAlgo, int keySize)`
    `static Signature` | `getSignature(PrivateKey key, String signAlgo, SecureRandom random, AlgorithmParameterSpec params)`
    `static Cipher` | `initCipher(Key secretKey, KeyProperties keyProps, int mode)`
    `static Certificate` | `loadCertificate(InputStream storeLocation, char[] storePassword, String alias, String storeType)`
    `static Certificate` | `loadCertificate(KeyStore keyStore, String alias)`
    `static KeyStore` | `loadKeyStore(InputStream storeLocation, char[] storePassword, String type)`
    `static PrivateKey` | `loadPrivateKey(InputStream storeLocation, char[] storePassword, char[] keyPassword, String alias, String storeType)`
    `static PrivateKey` | `loadPrivateKey(KeyStore keyStore, char[] keyPassword, String alias)`
    `static PublicKey` | `loadPublicKey(InputStream storeLocation, char[] storePassword, String alias, String storeType)`
    `static PublicKey` | `loadPublicKey(KeyStore keyStore, String alias)`
    `static byte[]` | `signData(byte[] data, PrivateKey key, String signAlgo)`
    `static byte[]` | `signData(byte[] data, PrivateKey key, String signAlgo, SecureRandom random, AlgorithmParameterSpec params)`
    `static Key` | `unwrapKey(byte[] wrappedBytes, String wrappedKeyAlgo, Key unwrapperKey, KeyProperties keyProps, int wrappedKeyType)`
    `static SecretKey` | `unwrapSecretKey(byte[] wrappedBytes, String wrappedKeyAlgo, Key unwrapperKey, KeyProperties keyProps)`
    `static SecretKey` | `unwrapSecretKey(byte[] wrappedBytes, String wrappedKeyAlgo, Key unwrapperKey, String unwrapperKeyAlgo)`
    `static boolean` | `verifySignature(byte[] data, byte[] signature, PublicKey key, String signAlgo)`
    `static boolean` | `verifySignature(byte[] data, byte[] signature, PublicKey key, String signAlgo, AlgorithmParameterSpec params)`
    `static byte[]` | `wrapSecretKey(byte[] keyBytes, String keyAlgo, Key wrapperKey, KeyProperties wrapperKeyProps)`
    `static byte[]` | `wrapSecretKey(Key secretKey, Key wrapperKey, KeyProperties keyProps)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### encodeSecretKey

          public static String encodeSecretKey(SecretKey key)
                                        throws SecurityException

      Throws:
        `SecurityException`

    - #### encryptSecretKey

          public static String encryptSecretKey(SecretKey secretKey,
                                PublicKey publicKey)
                                         throws SecurityException

      Throws:
        `SecurityException`

    - #### encryptSecretKey

          public static String encryptSecretKey(SecretKey secretKey,
                                PublicKey publicKey,
                                KeyProperties props)
                                         throws SecurityException

      Throws:
        `SecurityException`

    - #### generateSecureRandomBytes

          public static byte[] generateSecureRandomBytes(int size)

    - #### getRSAPublicKey

          public static RSAPublicKey getRSAPublicKey(String encodedModulus,
                                     String encodedPublicExponent)

    - #### getRSAPublicKey

          public static RSAPublicKey getRSAPublicKey(byte[] modulusBytes,
                                     byte[] publicExponentBytes)

    - #### getRSAPublicKey

          public static RSAPublicKey getRSAPublicKey(KeyFactory factory,
                                     byte[] modulusBytes,
                                     byte[] publicExponentBytes)

    - #### getRSAPrivateKey

          public static RSAPrivateKey getRSAPrivateKey(String encodedModulus,
                                       String encodedPrivateExponent)

    - #### getRSAPrivateKey

          public static RSAPrivateKey getRSAPrivateKey(byte[] modulusBytes,
                                       byte[] privateExponentBytes)

    - #### getRSAPrivateKey

          public static RSAPrivateKey getRSAPrivateKey(String encodedModulus,
                                       String encodedPublicExponent,
                                       String encodedPrivateExponent,
                                       String encodedPrimeP,
                                       String encodedPrimeQ,
                                       String encodedPrimeExpP,
                                       String encodedPrimeExpQ,
                                       String encodedCrtCoefficient)

    - #### getRSAPrivateKey

          public static RSAPrivateKey getRSAPrivateKey(byte[] modulusBytes,
                                       byte[] publicExponentBytes,
                                       byte[] privateExponentBytes,
                                       byte[] primePBytes,
                                       byte[] primeQBytes,
                                       byte[] primeExpPBytes,
                                       byte[] primeExpQBytes,
                                       byte[] crtCoefficientBytes)

    - #### getECPrivateKey

          public static ECPrivateKey getECPrivateKey(String curve,
                                     String encodedPrivateKey)

    - #### getECPrivateKey

          public static ECPrivateKey getECPrivateKey(String curve,
                                     byte[] privateKey)

    - #### generateECKeyPair

          public static KeyPair generateECKeyPair(String curve)

    - #### getECPublicKey

          public static ECPublicKey getECPublicKey(String curve,
                                   String encodedXPoint,
                                   String encodedYPoint)

    - #### getECPublicKey

          public static ECPublicKey getECPublicKey(String curve,
                                   byte[] xPoint,
                                   byte[] yPoint)

    - #### getContentEncryptionCipherSpec

          public static AlgorithmParameterSpec getContentEncryptionCipherSpec(int authTagLength,
                                                              byte[] iv)

    - #### getGCMParameterSpec

          public static AlgorithmParameterSpec getGCMParameterSpec(int authTagLength,
                                                   byte[] iv)

    - #### signData

          public static byte[] signData(byte[] data,
                        PrivateKey key,
                        String signAlgo)

    - #### signData

          public static byte[] signData(byte[] data,
                        PrivateKey key,
                        String signAlgo,
                        SecureRandom random,
                        AlgorithmParameterSpec params)

    - #### getSignature

          public static Signature getSignature(PrivateKey key,
                               String signAlgo,
                               SecureRandom random,
                               AlgorithmParameterSpec params)

    - #### verifySignature

          public static boolean verifySignature(byte[] data,
                                byte[] signature,
                                PublicKey key,
                                String signAlgo)

    - #### verifySignature

          public static boolean verifySignature(byte[] data,
                                byte[] signature,
                                PublicKey key,
                                String signAlgo,
                                AlgorithmParameterSpec params)

    - #### getSecretKey

          public static SecretKey getSecretKey(String symEncAlgo)
                                        throws SecurityException

      Throws:
        `SecurityException`

    - #### getSecretKey

          public static SecretKey getSecretKey(String symEncAlgo,
                               int keySize)
                                        throws SecurityException

      Throws:
        `SecurityException`

    - #### getSecretKey

          public static SecretKey getSecretKey(KeyProperties props)
                                        throws SecurityException

      Throws:
        `SecurityException`

    - #### decryptSequence

          public static String decryptSequence(String encodedToken,
                               String encodedSecretKey)
                                        throws SecurityException

      Throws:
        `SecurityException`

    - #### decryptSequence

          public static String decryptSequence(String encodedData,
                               String encodedSecretKey,
                               KeyProperties props)
                                        throws SecurityException

      Throws:
        `SecurityException`

    - #### decryptSequence

          public static String decryptSequence(String encodedData,
                               Key secretKey)
                                        throws SecurityException

      Throws:
        `SecurityException`

    - #### decryptSequence

          public static String decryptSequence(String encodedData,
                               Key secretKey,
                               KeyProperties props)
                                        throws SecurityException

      Throws:
        `SecurityException`

    - #### encryptSequence

          public static String encryptSequence(String sequence,
                               Key secretKey)
                                        throws SecurityException

      Throws:
        `SecurityException`

    - #### encryptSequence

          public static String encryptSequence(String sequence,
                               Key secretKey,
                               KeyProperties keyProps)
                                        throws SecurityException

      Throws:
        `SecurityException`

    - #### encodeBytes

          public static String encodeBytes(byte[] bytes)
                                    throws SecurityException

      Throws:
        `SecurityException`

    - #### encryptBytes

          public static byte[] encryptBytes(byte[] bytes,
                            Key secretKey)
                                     throws SecurityException

      Throws:
        `SecurityException`

    - #### encryptBytes

          public static byte[] encryptBytes(byte[] bytes,
                            Key secretKey,
                            KeyProperties keyProps)
                                     throws SecurityException

      Throws:
        `SecurityException`

    - #### decryptBytes

          public static byte[] decryptBytes(byte[] bytes,
                            Key secretKey)
                                     throws SecurityException

      Throws:
        `SecurityException`

    - #### decryptBytes

          public static byte[] decryptBytes(byte[] bytes,
                            Key secretKey,
                            KeyProperties keyProps)
                                     throws SecurityException

      Throws:
        `SecurityException`

    - #### wrapSecretKey

          public static byte[] wrapSecretKey(byte[] keyBytes,
                             String keyAlgo,
                             Key wrapperKey,
                             KeyProperties wrapperKeyProps)
                                      throws SecurityException

      Throws:
        `SecurityException`

    - #### wrapSecretKey

          public static byte[] wrapSecretKey(Key secretKey,
                             Key wrapperKey,
                             KeyProperties keyProps)
                                      throws SecurityException

      Throws:
        `SecurityException`

    - #### unwrapSecretKey

          public static SecretKey unwrapSecretKey(byte[] wrappedBytes,
                                  String wrappedKeyAlgo,
                                  Key unwrapperKey,
                                  String unwrapperKeyAlgo)
                                           throws SecurityException

      Throws:
        `SecurityException`

    - #### unwrapSecretKey

          public static SecretKey unwrapSecretKey(byte[] wrappedBytes,
                                  String wrappedKeyAlgo,
                                  Key unwrapperKey,
                                  KeyProperties keyProps)
                                           throws SecurityException

      Throws:
        `SecurityException`

    - #### unwrapKey

          public static Key unwrapKey(byte[] wrappedBytes,
                      String wrappedKeyAlgo,
                      Key unwrapperKey,
                      KeyProperties keyProps,
                      int wrappedKeyType)
                               throws SecurityException

      Throws:
        `SecurityException`

    - #### initCipher

          public static Cipher initCipher(Key secretKey,
                          KeyProperties keyProps,
                          int mode)
                                   throws SecurityException

      Throws:
        `SecurityException`

    - #### decodeSecretKey

          public static SecretKey decodeSecretKey(String encodedSecretKey)
                                           throws SecurityException

      Throws:
        `SecurityException`

    - #### decodeSecretKey

          public static SecretKey decodeSecretKey(String encodedSecretKey,
                                  String secretKeyAlgo)
                                           throws SecurityException

      Throws:
        `SecurityException`

    - #### decryptSecretKey

          public static SecretKey decryptSecretKey(String encodedEncryptedSecretKey,
                                   PrivateKey privateKey)

    - #### decryptSecretKey

          public static SecretKey decryptSecretKey(String encodedEncryptedSecretKey,
                                   String secretKeyAlgo,
                                   PrivateKey privateKey)
                                            throws SecurityException

      Throws:
        `SecurityException`

    - #### decryptSecretKey

          public static SecretKey decryptSecretKey(String encodedEncryptedSecretKey,
                                   String secretKeyAlgo,
                                   KeyProperties props,
                                   PrivateKey privateKey)
                                            throws SecurityException

      Throws:
        `SecurityException`

    - #### createSecretKeySpec

          public static SecretKey createSecretKeySpec(String encodedBytes,
                                      String algo)

    - #### createSecretKeySpec

          public static SecretKey createSecretKeySpec(byte[] bytes,
                                      String algo)

    - #### decodeSequence

          public static byte[] decodeSequence(String encodedSequence)
                                       throws SecurityException

      Throws:
        `SecurityException`

    - #### loadCertificate

          public static Certificate loadCertificate(InputStream storeLocation,
                                    char[] storePassword,
                                    String alias,
                                    String storeType)

    - #### loadCertificate

          public static Certificate loadCertificate(KeyStore keyStore,
                                    String alias)

    - #### encodeCertificate

          public static String encodeCertificate(Certificate cert)

    - #### decodeCertificate

          public static Certificate decodeCertificate(String encodedCert)

    - #### loadPublicKey

          public static PublicKey loadPublicKey(InputStream storeLocation,
                                char[] storePassword,
                                String alias,
                                String storeType)

    - #### loadPublicKey

          public static PublicKey loadPublicKey(KeyStore keyStore,
                                String alias)

    - #### loadKeyStore

          public static KeyStore loadKeyStore(InputStream storeLocation,
                              char[] storePassword,
                              String type)

    - #### loadPrivateKey

          public static PrivateKey loadPrivateKey(InputStream storeLocation,
                                  char[] storePassword,
                                  char[] keyPassword,
                                  String alias,
                                  String storeType)

    - #### loadPrivateKey

          public static PrivateKey loadPrivateKey(KeyStore keyStore,
                                  char[] keyPassword,
                                  String alias)

Apache CXF