public final class Crypto
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ALG_HASH |
static java.lang.String |
ALG_PUBLIC_KEY_GEN |
static java.lang.String |
ALG_SECRET_CRYPTO |
static java.lang.String |
ALG_SECRET_KEY_GEN |
static java.lang.String |
ALG_SIGNATURE |
static int |
SIZE_PUBLIC_KEY |
static int |
SIZE_SECRET_KEY |
Constructor and Description |
---|
Crypto() |
Modifier and Type | Method and Description |
---|---|
static javax.crypto.Cipher |
cipherInstance(int opmode,
byte[] key,
byte[] iv)
Creates an initializes a new Cipher instance with the given parameters.
|
static java.security.cert.X509Certificate |
createCertificate(java.lang.String subjectName,
java.security.PublicKey subjectKey,
java.lang.String issuerName,
java.security.PrivateKey issuerKey)
Generates a certificate, signed by the issuer, binding the subject's name
to their public key.
|
static java.security.MessageDigest |
digestInstance() |
static void |
fillIV(byte[] iv)
Fills an initialization vector with random bytes.
|
static java.security.KeyPair |
genKeyPair() |
static javax.crypto.SecretKey |
genSecretKey() |
static java.lang.String |
getCN(java.lang.String dn)
Extracts the CN component of a Distinguished Name.
|
static byte[] |
makeIV()
Creates a new initialization vector.
|
static java.security.KeyPairGenerator |
publicKeyGenInstance() |
static javax.crypto.KeyGenerator |
secretKeyGenInstance() |
static java.security.Signature |
signatureInstance() |
static void |
validateCertificateChain(java.security.cert.Certificate[] certificateChain,
java.util.Set<java.security.cert.TrustAnchor> trustStore)
Validates the given certificate chain against the given trust store.
|
public static final java.lang.String ALG_SIGNATURE
public static final java.lang.String ALG_SECRET_KEY_GEN
public static final int SIZE_SECRET_KEY
public static final java.lang.String ALG_SECRET_CRYPTO
public static final java.lang.String ALG_PUBLIC_KEY_GEN
public static final int SIZE_PUBLIC_KEY
public static final java.lang.String ALG_HASH
public static java.security.MessageDigest digestInstance()
public static java.security.Signature signatureInstance()
public static javax.crypto.KeyGenerator secretKeyGenInstance()
public static javax.crypto.SecretKey genSecretKey()
public static java.security.KeyPairGenerator publicKeyGenInstance()
public static java.security.KeyPair genKeyPair()
public static void fillIV(byte[] iv)
public static byte[] makeIV()
public static javax.crypto.Cipher cipherInstance(int opmode, byte[] key, byte[] iv) throws java.security.NoSuchAlgorithmException, javax.crypto.NoSuchPaddingException, java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
opmode
- The mode of operation. One of the mode constants in Cipher.key
- The secret key to use.iv
- The initialization vector to use. For encryption, this should be
randomly generated; for decryption, this should match the one used
during encryption.java.security.NoSuchAlgorithmException
javax.crypto.NoSuchPaddingException
java.security.InvalidKeyException
java.security.InvalidAlgorithmParameterException
public static void validateCertificateChain(java.security.cert.Certificate[] certificateChain, java.util.Set<java.security.cert.TrustAnchor> trustStore) throws java.security.GeneralSecurityException
java.security.GeneralSecurityException
public static java.security.cert.X509Certificate createCertificate(java.lang.String subjectName, java.security.PublicKey subjectKey, java.lang.String issuerName, java.security.PrivateKey issuerKey) throws java.security.GeneralSecurityException
java.security.GeneralSecurityException
public static java.lang.String getCN(java.lang.String dn)