public final class SecurityHelper
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
SecurityHelper.DigestAlgorithm |
| Modifier and Type | Field and Description |
|---|---|
static int |
AES_KEY_LENGTH |
static int |
CRYPTO_MAX_LENGTH |
static java.lang.String |
HEX |
static byte[] |
NUMBERS |
static java.lang.String |
RSA_ALGO |
static java.lang.String |
RSA_CIPHER_ALGO |
static int |
RSA_KEY_LENGTH |
static int |
RSA_KEY_LENGTH_BITS |
static java.lang.String |
RSA_SIGN_ALGO |
static java.security.SecureRandom |
secureRandom |
static int |
TOKEN_LENGTH |
static int |
TOKEN_STRING_LENGTH |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
decrypt(byte[] raw,
byte[] encrypted) |
static byte[] |
digest(SecurityHelper.DigestAlgorithm algo,
byte[] bytes) |
static byte[] |
digest(SecurityHelper.DigestAlgorithm algo,
java.io.InputStream input) |
static byte[] |
digest(SecurityHelper.DigestAlgorithm algo,
java.nio.file.Path file) |
static byte[] |
digest(SecurityHelper.DigestAlgorithm algo,
java.lang.String s) |
static byte[] |
digest(SecurityHelper.DigestAlgorithm algo,
java.net.URL url) |
static byte[] |
encrypt(byte[] raw,
byte[] clear) |
static byte[] |
encrypt(java.lang.String seed,
byte[] cleartext) |
static byte[] |
encrypt(java.lang.String seed,
java.lang.String cleartext) |
static java.security.KeyPair |
genRSAKeyPair() |
static java.security.KeyPair |
genRSAKeyPair(java.security.SecureRandom random) |
static byte[] |
HexToByte(java.lang.String hexString) |
static boolean |
isValidSign(byte[] bytes,
byte[] sign,
java.security.interfaces.RSAPublicKey publicKey) |
static boolean |
isValidSign(java.io.InputStream input,
byte[] sign,
java.security.interfaces.RSAPublicKey publicKey) |
static boolean |
isValidSign(java.nio.file.Path path,
byte[] sign,
java.security.interfaces.RSAPublicKey publicKey) |
static boolean |
isValidSign(java.net.URL url,
byte[] sign,
java.security.interfaces.RSAPublicKey publicKey) |
static boolean |
isValidToken(java.lang.CharSequence token) |
static java.security.MessageDigest |
newDigest(SecurityHelper.DigestAlgorithm algo) |
static java.security.SecureRandom |
newRandom() |
static javax.crypto.Cipher |
newRSADecryptCipher(java.security.interfaces.RSAPrivateKey key) |
static javax.crypto.Cipher |
newRSAEncryptCipher(java.security.interfaces.RSAPublicKey key) |
static java.security.Signature |
newRSASignSignature(java.security.interfaces.RSAPrivateKey key) |
static java.security.Signature |
newRSAVerifySignature(java.security.interfaces.RSAPublicKey key) |
static byte[] |
randomAESKey() |
static byte[] |
randomAESKey(java.util.Random random) |
static byte[] |
randomBytes(int length) |
static byte[] |
randomBytes(java.util.Random random,
int length) |
static java.lang.String |
randomStringAESKey() |
static java.lang.String |
randomStringAESKey(java.util.Random random) |
static java.lang.String |
randomStringToken() |
static java.lang.String |
randomStringToken(java.util.Random random) |
static byte[] |
randomToken() |
static byte[] |
randomToken(java.util.Random random) |
static java.lang.String |
randomUsername() |
static java.lang.String |
randomUsername(java.util.Random random) |
static byte[] |
sign(byte[] bytes,
java.security.interfaces.RSAPrivateKey privateKey) |
static byte[] |
sign(java.io.InputStream input,
java.security.interfaces.RSAPrivateKey privateKey) |
static byte[] |
sign(java.nio.file.Path path,
java.security.interfaces.RSAPrivateKey privateKey) |
static java.lang.String |
toHex(byte[] bytes) |
static java.security.interfaces.RSAPrivateKey |
toPrivateRSAKey(byte[] bytes) |
static java.security.interfaces.RSAPublicKey |
toPublicRSAKey(byte[] bytes) |
static void |
verifySign(byte[] bytes,
byte[] sign,
java.security.interfaces.RSAPublicKey publicKey) |
static void |
verifySign(java.io.InputStream input,
byte[] sign,
java.security.interfaces.RSAPublicKey publicKey) |
static void |
verifySign(java.nio.file.Path path,
byte[] sign,
java.security.interfaces.RSAPublicKey publicKey) |
static void |
verifySign(java.net.URL url,
byte[] sign,
java.security.interfaces.RSAPublicKey publicKey) |
static java.lang.String |
verifyToken(java.lang.String token) |
public static final java.lang.String RSA_ALGO
public static final java.lang.String RSA_SIGN_ALGO
public static final java.lang.String RSA_CIPHER_ALGO
public static final int TOKEN_LENGTH
public static final int AES_KEY_LENGTH
public static final int TOKEN_STRING_LENGTH
public static final int RSA_KEY_LENGTH_BITS
public static final int RSA_KEY_LENGTH
public static final int CRYPTO_MAX_LENGTH
public static final java.lang.String HEX
public static final byte[] NUMBERS
public static final java.security.SecureRandom secureRandom
public static byte[] digest(SecurityHelper.DigestAlgorithm algo, byte[] bytes)
public static byte[] digest(SecurityHelper.DigestAlgorithm algo, java.io.InputStream input) throws java.io.IOException
java.io.IOExceptionpublic static byte[] digest(SecurityHelper.DigestAlgorithm algo, java.nio.file.Path file) throws java.io.IOException
java.io.IOExceptionpublic static byte[] digest(SecurityHelper.DigestAlgorithm algo, java.lang.String s)
public static byte[] digest(SecurityHelper.DigestAlgorithm algo, java.net.URL url) throws java.io.IOException
java.io.IOExceptionpublic static java.security.KeyPair genRSAKeyPair()
public static java.security.KeyPair genRSAKeyPair(java.security.SecureRandom random)
public static boolean isValidSign(byte[] bytes,
byte[] sign,
java.security.interfaces.RSAPublicKey publicKey)
throws java.security.SignatureException
java.security.SignatureExceptionpublic static boolean isValidSign(java.io.InputStream input,
byte[] sign,
java.security.interfaces.RSAPublicKey publicKey)
throws java.io.IOException,
java.security.SignatureException
java.io.IOExceptionjava.security.SignatureExceptionpublic static boolean isValidSign(java.nio.file.Path path,
byte[] sign,
java.security.interfaces.RSAPublicKey publicKey)
throws java.io.IOException,
java.security.SignatureException
java.io.IOExceptionjava.security.SignatureExceptionpublic static boolean isValidSign(java.net.URL url,
byte[] sign,
java.security.interfaces.RSAPublicKey publicKey)
throws java.io.IOException,
java.security.SignatureException
java.io.IOExceptionjava.security.SignatureExceptionpublic static boolean isValidToken(java.lang.CharSequence token)
public static java.security.MessageDigest newDigest(SecurityHelper.DigestAlgorithm algo)
public static java.security.SecureRandom newRandom()
public static javax.crypto.Cipher newRSADecryptCipher(java.security.interfaces.RSAPrivateKey key)
public static javax.crypto.Cipher newRSAEncryptCipher(java.security.interfaces.RSAPublicKey key)
public static java.security.Signature newRSASignSignature(java.security.interfaces.RSAPrivateKey key)
public static java.security.Signature newRSAVerifySignature(java.security.interfaces.RSAPublicKey key)
public static byte[] randomBytes(int length)
public static byte[] randomBytes(java.util.Random random,
int length)
public static java.lang.String randomStringToken()
public static java.lang.String randomStringToken(java.util.Random random)
public static byte[] randomToken()
public static byte[] randomToken(java.util.Random random)
public static java.lang.String randomStringAESKey()
public static java.lang.String randomStringAESKey(java.util.Random random)
public static byte[] randomAESKey()
public static byte[] randomAESKey(java.util.Random random)
public static java.lang.String randomUsername()
public static java.lang.String randomUsername(java.util.Random random)
public static byte[] sign(byte[] bytes,
java.security.interfaces.RSAPrivateKey privateKey)
public static byte[] sign(java.io.InputStream input,
java.security.interfaces.RSAPrivateKey privateKey)
throws java.io.IOException
java.io.IOExceptionpublic static byte[] sign(java.nio.file.Path path,
java.security.interfaces.RSAPrivateKey privateKey)
throws java.io.IOException
java.io.IOExceptionpublic static java.lang.String toHex(byte[] bytes)
public static java.security.interfaces.RSAPrivateKey toPrivateRSAKey(byte[] bytes)
throws java.security.spec.InvalidKeySpecException
java.security.spec.InvalidKeySpecExceptionpublic static java.security.interfaces.RSAPublicKey toPublicRSAKey(byte[] bytes)
throws java.security.spec.InvalidKeySpecException
java.security.spec.InvalidKeySpecExceptionpublic static void verifySign(byte[] bytes,
byte[] sign,
java.security.interfaces.RSAPublicKey publicKey)
throws java.security.SignatureException
java.security.SignatureExceptionpublic static void verifySign(java.io.InputStream input,
byte[] sign,
java.security.interfaces.RSAPublicKey publicKey)
throws java.security.SignatureException,
java.io.IOException
java.security.SignatureExceptionjava.io.IOExceptionpublic static void verifySign(java.nio.file.Path path,
byte[] sign,
java.security.interfaces.RSAPublicKey publicKey)
throws java.security.SignatureException,
java.io.IOException
java.security.SignatureExceptionjava.io.IOExceptionpublic static void verifySign(java.net.URL url,
byte[] sign,
java.security.interfaces.RSAPublicKey publicKey)
throws java.security.SignatureException,
java.io.IOException
java.security.SignatureExceptionjava.io.IOExceptionpublic static java.lang.String verifyToken(java.lang.String token)
public static byte[] encrypt(java.lang.String seed,
byte[] cleartext)
throws java.lang.Exception
java.lang.Exceptionpublic static byte[] encrypt(java.lang.String seed,
java.lang.String cleartext)
throws java.lang.Exception
java.lang.Exceptionpublic static byte[] encrypt(byte[] raw,
byte[] clear)
throws java.lang.Exception
java.lang.Exceptionpublic static byte[] decrypt(byte[] raw,
byte[] encrypted)
throws java.lang.Exception
java.lang.Exceptionpublic static byte[] HexToByte(java.lang.String hexString)