Class CryptoUtils
- java.lang.Object
-
- org.apache.cxf.rt.security.crypto.CryptoUtils
-
public final class CryptoUtils extends Object
Encryption helpers
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static SecretKeycreateSecretKeySpec(byte[] bytes, String algo)static SecretKeycreateSecretKeySpec(String encodedBytes, String algo)static CertificatedecodeCertificate(String encodedCert)static SecretKeydecodeSecretKey(String encodedSecretKey)static SecretKeydecodeSecretKey(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 SecretKeydecryptSecretKey(String encodedEncryptedSecretKey, String secretKeyAlgo, PrivateKey privateKey)static SecretKeydecryptSecretKey(String encodedEncryptedSecretKey, String secretKeyAlgo, KeyProperties props, PrivateKey privateKey)static SecretKeydecryptSecretKey(String encodedEncryptedSecretKey, PrivateKey privateKey)static StringdecryptSequence(String encodedToken, String encodedSecretKey)static StringdecryptSequence(String encodedData, String encodedSecretKey, KeyProperties props)static StringdecryptSequence(String encodedData, Key secretKey)static StringdecryptSequence(String encodedData, Key secretKey, KeyProperties props)static StringencodeBytes(byte[] bytes)static StringencodeCertificate(Certificate cert)static StringencodeSecretKey(SecretKey key)static byte[]encryptBytes(byte[] bytes, Key secretKey)static byte[]encryptBytes(byte[] bytes, Key secretKey, KeyProperties keyProps)static StringencryptSecretKey(SecretKey secretKey, PublicKey publicKey)static StringencryptSecretKey(SecretKey secretKey, PublicKey publicKey, KeyProperties props)static StringencryptSequence(String sequence, Key secretKey)static StringencryptSequence(String sequence, Key secretKey, KeyProperties keyProps)static KeyPairgenerateECKeyPair(String curve)static byte[]generateSecureRandomBytes(int size)static AlgorithmParameterSpecgetContentEncryptionCipherSpec(int authTagLength, byte[] iv)static ECPrivateKeygetECPrivateKey(String curve, byte[] privateKey)static ECPrivateKeygetECPrivateKey(String curve, String encodedPrivateKey)static ECPublicKeygetECPublicKey(String curve, byte[] xPoint, byte[] yPoint)static ECPublicKeygetECPublicKey(String curve, String encodedXPoint, String encodedYPoint)static AlgorithmParameterSpecgetGCMParameterSpec(int authTagLength, byte[] iv)static RSAPrivateKeygetRSAPrivateKey(byte[] modulusBytes, byte[] privateExponentBytes)static RSAPrivateKeygetRSAPrivateKey(byte[] modulusBytes, byte[] publicExponentBytes, byte[] privateExponentBytes, byte[] primePBytes, byte[] primeQBytes, byte[] primeExpPBytes, byte[] primeExpQBytes, byte[] crtCoefficientBytes)static RSAPrivateKeygetRSAPrivateKey(String encodedModulus, String encodedPrivateExponent)static RSAPrivateKeygetRSAPrivateKey(String encodedModulus, String encodedPublicExponent, String encodedPrivateExponent, String encodedPrimeP, String encodedPrimeQ, String encodedPrimeExpP, String encodedPrimeExpQ, String encodedCrtCoefficient)static RSAPublicKeygetRSAPublicKey(byte[] modulusBytes, byte[] publicExponentBytes)static RSAPublicKeygetRSAPublicKey(String encodedModulus, String encodedPublicExponent)static RSAPublicKeygetRSAPublicKey(BigInteger modulusBytes, BigInteger publicExponentBytes)static RSAPublicKeygetRSAPublicKey(KeyFactory factory, byte[] modulusBytes, byte[] publicExponentBytes)static RSAPublicKeygetRSAPublicKey(KeyFactory factory, BigInteger modulus, BigInteger publicExponent)static SecretKeygetSecretKey(String symEncAlgo)static SecretKeygetSecretKey(String symEncAlgo, int keySize)static SecretKeygetSecretKey(KeyProperties props)static SignaturegetSignature(PrivateKey key, String signAlgo, SecureRandom random, AlgorithmParameterSpec params)static SignaturegetVerificationSignature(PublicKey key, String signAlgo, AlgorithmParameterSpec params)static CipherinitCipher(Key secretKey, KeyProperties keyProps, int mode)static voidinstallBouncyCastleProvider()static CertificateloadCertificate(InputStream storeLocation, char[] storePassword, String alias, String storeType)static CertificateloadCertificate(KeyStore keyStore, String alias)static KeyStoreloadKeyStore(InputStream storeLocation, char[] storePassword, String type)static PrivateKeyloadPrivateKey(InputStream storeLocation, char[] storePassword, char[] keyPassword, String alias, String storeType)static PrivateKeyloadPrivateKey(KeyStore keyStore, char[] keyPassword, String alias)static PublicKeyloadPublicKey(InputStream storeLocation, char[] storePassword, String alias, String storeType)static PublicKeyloadPublicKey(KeyStore keyStore, String alias)static voidremoveBouncyCastleProvider()static byte[]signData(byte[] data, PrivateKey key, String signAlgo)static byte[]signData(byte[] data, PrivateKey key, String signAlgo, SecureRandom random, AlgorithmParameterSpec params)static KeyunwrapKey(byte[] wrappedBytes, String wrappedKeyAlgo, Key unwrapperKey, KeyProperties keyProps, int wrappedKeyType)static SecretKeyunwrapSecretKey(byte[] wrappedBytes, String wrappedKeyAlgo, Key unwrapperKey, String unwrapperKeyAlgo)static SecretKeyunwrapSecretKey(byte[] wrappedBytes, String wrappedKeyAlgo, Key unwrapperKey, KeyProperties keyProps)static booleanverifySignature(byte[] data, byte[] signature, PublicKey key, String signAlgo)static booleanverifySignature(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)
-
-
-
Method Detail
-
installBouncyCastleProvider
public static void installBouncyCastleProvider() throws Exception- Throws:
Exception
-
removeBouncyCastleProvider
public static void removeBouncyCastleProvider()
-
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)
-
getRSAPublicKey
public static RSAPublicKey getRSAPublicKey(BigInteger modulusBytes, BigInteger publicExponentBytes)
-
getRSAPublicKey
public static RSAPublicKey getRSAPublicKey(KeyFactory factory, BigInteger modulus, BigInteger publicExponent)
-
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)
-
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)
-
getVerificationSignature
public static Signature getVerificationSignature(PublicKey key, String signAlgo, 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
-
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)
-
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)
-
-