Package pro.gravit.utils.helper
Class SecurityHelper
- java.lang.Object
-
- pro.gravit.utils.helper.SecurityHelper
-
public final class SecurityHelper extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSecurityHelper.DigestAlgorithm
-
Field Summary
Fields Modifier and Type Field Description static intAES_KEY_LENGTHstatic intCRYPTO_MAX_LENGTHstatic java.lang.StringEC_ALGOstatic java.lang.StringEC_CIPHER_ALGOstatic java.lang.StringEC_CURVEstatic java.lang.StringEC_SIGN_ALGOstatic java.lang.StringHEXstatic byte[]NUMBERSstatic intRSA_KEY_LENGTHstatic intRSA_KEY_LENGTH_BITSstatic java.security.SecureRandomsecureRandomstatic intTOKEN_LENGTHstatic intTOKEN_STRING_LENGTH
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]decrypt(byte[] raw, byte[] encrypted)static byte[]decrypt(java.lang.String seed, 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.lang.String s)static byte[]digest(SecurityHelper.DigestAlgorithm algo, java.net.URL url)static byte[]digest(SecurityHelper.DigestAlgorithm algo, java.nio.file.Path file)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 byte[]fromHex(java.lang.String hexString)static java.security.KeyPairgenECKeyPair(java.security.SecureRandom random)static booleanisValidSign(byte[] bytes, byte[] sign, java.security.interfaces.ECPublicKey publicKey)static booleanisValidSign(java.io.InputStream input, byte[] sign, java.security.interfaces.ECPublicKey publicKey)static booleanisValidToken(java.lang.CharSequence token)static javax.crypto.CiphernewCipher(java.lang.String algo)static java.security.MessageDigestnewDigest(SecurityHelper.DigestAlgorithm algo)static javax.crypto.CiphernewECDecryptCipher(java.security.interfaces.ECPrivateKey privateKey)static javax.crypto.CiphernewECEncryptCipher(java.security.interfaces.ECPublicKey publicKey)static java.security.SignaturenewECSignSignature(java.security.interfaces.ECPrivateKey key)static java.security.SignaturenewECVerifySignature(java.security.interfaces.ECPublicKey key)static java.security.SecureRandomnewRandom()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.StringrandomStringAESKey()static java.lang.StringrandomStringAESKey(java.util.Random random)static java.lang.StringrandomStringToken()static java.lang.StringrandomStringToken(java.util.Random random)static byte[]randomToken()static byte[]randomToken(java.util.Random random)static java.lang.StringrandomUsername()static java.lang.StringrandomUsername(java.util.Random random)static byte[]sign(byte[] bytes, java.security.interfaces.ECPrivateKey privateKey)static java.lang.StringtoHex(byte[] bytes)static java.security.interfaces.ECPrivateKeytoPrivateECKey(byte[] bytes)static java.security.interfaces.ECPublicKeytoPublicECKey(byte[] bytes)static voidverifySign(byte[] bytes, byte[] sign, java.security.interfaces.ECPublicKey publicKey)static voidverifySign(java.io.InputStream input, byte[] sign, java.security.interfaces.ECPublicKey publicKey)static java.lang.StringverifyToken(java.lang.String token)
-
-
-
Field Detail
-
EC_ALGO
public static final java.lang.String EC_ALGO
- See Also:
- Constant Field Values
-
EC_CURVE
public static final java.lang.String EC_CURVE
- See Also:
- Constant Field Values
-
EC_SIGN_ALGO
public static final java.lang.String EC_SIGN_ALGO
- See Also:
- Constant Field Values
-
EC_CIPHER_ALGO
public static final java.lang.String EC_CIPHER_ALGO
- See Also:
- Constant Field Values
-
TOKEN_LENGTH
public static final int TOKEN_LENGTH
- See Also:
- Constant Field Values
-
AES_KEY_LENGTH
public static final int AES_KEY_LENGTH
- See Also:
- Constant Field Values
-
TOKEN_STRING_LENGTH
public static final int TOKEN_STRING_LENGTH
- See Also:
- Constant Field Values
-
RSA_KEY_LENGTH_BITS
public static final int RSA_KEY_LENGTH_BITS
- See Also:
- Constant Field Values
-
RSA_KEY_LENGTH
public static final int RSA_KEY_LENGTH
- See Also:
- Constant Field Values
-
CRYPTO_MAX_LENGTH
public static final int CRYPTO_MAX_LENGTH
- See Also:
- Constant Field Values
-
HEX
public static final java.lang.String HEX
- See Also:
- Constant Field Values
-
NUMBERS
public static final byte[] NUMBERS
-
secureRandom
public static final java.security.SecureRandom secureRandom
-
-
Method Detail
-
digest
public static byte[] digest(SecurityHelper.DigestAlgorithm algo, byte[] bytes)
-
digest
public static byte[] digest(SecurityHelper.DigestAlgorithm algo, java.io.InputStream input) throws java.io.IOException
- Throws:
java.io.IOException
-
digest
public static byte[] digest(SecurityHelper.DigestAlgorithm algo, java.nio.file.Path file) throws java.io.IOException
- Throws:
java.io.IOException
-
digest
public static byte[] digest(SecurityHelper.DigestAlgorithm algo, java.lang.String s)
-
digest
public static byte[] digest(SecurityHelper.DigestAlgorithm algo, java.net.URL url) throws java.io.IOException
- Throws:
java.io.IOException
-
genECKeyPair
public static java.security.KeyPair genECKeyPair(java.security.SecureRandom random)
-
isValidSign
public static boolean isValidSign(byte[] bytes, byte[] sign, java.security.interfaces.ECPublicKey publicKey) throws java.security.SignatureException- Throws:
java.security.SignatureException
-
isValidSign
public static boolean isValidSign(java.io.InputStream input, byte[] sign, java.security.interfaces.ECPublicKey publicKey) throws java.io.IOException, java.security.SignatureException- Throws:
java.io.IOExceptionjava.security.SignatureException
-
isValidToken
public static boolean isValidToken(java.lang.CharSequence token)
-
newCipher
public static javax.crypto.Cipher newCipher(java.lang.String algo)
-
newDigest
public static java.security.MessageDigest newDigest(SecurityHelper.DigestAlgorithm algo)
-
newRandom
public static java.security.SecureRandom newRandom()
-
newECSignSignature
public static java.security.Signature newECSignSignature(java.security.interfaces.ECPrivateKey key)
-
newECVerifySignature
public static java.security.Signature newECVerifySignature(java.security.interfaces.ECPublicKey key)
-
randomBytes
public static byte[] randomBytes(int length)
-
randomBytes
public static byte[] randomBytes(java.util.Random random, int length)
-
randomStringToken
public static java.lang.String randomStringToken()
-
randomStringToken
public static java.lang.String randomStringToken(java.util.Random random)
-
randomToken
public static byte[] randomToken()
-
randomToken
public static byte[] randomToken(java.util.Random random)
-
randomStringAESKey
public static java.lang.String randomStringAESKey()
-
randomStringAESKey
public static java.lang.String randomStringAESKey(java.util.Random random)
-
randomAESKey
public static byte[] randomAESKey()
-
randomAESKey
public static byte[] randomAESKey(java.util.Random random)
-
randomUsername
public static java.lang.String randomUsername()
-
randomUsername
public static java.lang.String randomUsername(java.util.Random random)
-
sign
public static byte[] sign(byte[] bytes, java.security.interfaces.ECPrivateKey privateKey)
-
toHex
public static java.lang.String toHex(byte[] bytes)
-
toPublicECKey
public static java.security.interfaces.ECPublicKey toPublicECKey(byte[] bytes) throws java.security.spec.InvalidKeySpecException- Throws:
java.security.spec.InvalidKeySpecException
-
toPrivateECKey
public static java.security.interfaces.ECPrivateKey toPrivateECKey(byte[] bytes) throws java.security.spec.InvalidKeySpecException- Throws:
java.security.spec.InvalidKeySpecException
-
verifySign
public static void verifySign(byte[] bytes, byte[] sign, java.security.interfaces.ECPublicKey publicKey) throws java.security.SignatureException- Throws:
java.security.SignatureException
-
verifySign
public static void verifySign(java.io.InputStream input, byte[] sign, java.security.interfaces.ECPublicKey publicKey) throws java.security.SignatureException, java.io.IOException- Throws:
java.security.SignatureExceptionjava.io.IOException
-
verifyToken
public static java.lang.String verifyToken(java.lang.String token)
-
newECDecryptCipher
public static javax.crypto.Cipher newECDecryptCipher(java.security.interfaces.ECPrivateKey privateKey)
-
newECEncryptCipher
public static javax.crypto.Cipher newECEncryptCipher(java.security.interfaces.ECPublicKey publicKey)
-
encrypt
public static byte[] encrypt(java.lang.String seed, byte[] cleartext) throws java.lang.Exception- Throws:
java.lang.Exception
-
encrypt
public static byte[] encrypt(java.lang.String seed, java.lang.String cleartext) throws java.lang.Exception- Throws:
java.lang.Exception
-
encrypt
public static byte[] encrypt(byte[] raw, byte[] clear) throws java.lang.Exception- Throws:
java.lang.Exception
-
decrypt
public static byte[] decrypt(byte[] raw, byte[] encrypted) throws java.lang.Exception- Throws:
java.lang.Exception
-
decrypt
public static byte[] decrypt(java.lang.String seed, byte[] encrypted) throws java.lang.Exception- Throws:
java.lang.Exception
-
fromHex
public static byte[] fromHex(java.lang.String hexString)
-
-