Package pro.gravit.utils.helper
Class SecurityHelper
java.lang.Object
pro.gravit.utils.helper.SecurityHelper
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]decrypt(byte[] raw, byte[] encrypted)static byte[]static byte[]digest(SecurityHelper.DigestAlgorithm algo, byte[] bytes)static byte[]digest(SecurityHelper.DigestAlgorithm algo, InputStream input)static byte[]digest(SecurityHelper.DigestAlgorithm algo, String s)static byte[]digest(SecurityHelper.DigestAlgorithm algo, URL url)static byte[]digest(SecurityHelper.DigestAlgorithm algo, Path file)static byte[]encrypt(byte[] raw, byte[] clear)static byte[]static byte[]static byte[]static KeyPairgenECDSAKeyPair(SecureRandom random)static KeyPairgenECKeyPair(SecureRandom random)Deprecated.static KeyPairgenRSAKeyPair(SecureRandom random)static byte[]getAESKey(byte[] seed)static booleanisValidSign(byte[] bytes, byte[] sign, ECPublicKey publicKey)static booleanisValidSign(byte[] bytes, byte[] sign, RSAPublicKey publicKey)static booleanisValidSign(InputStream input, byte[] sign, ECPublicKey publicKey)static booleanisValidSign(InputStream input, byte[] sign, RSAPublicKey publicKey)static booleanisValidToken(CharSequence token)static Cipherstatic MessageDigeststatic Signaturestatic Signaturestatic SecureRandomstatic CiphernewRSADecryptCipher(RSAPrivateKey privateKey)static CiphernewRSAEncryptCipher(RSAPublicKey publicKey)static Signaturestatic Signaturestatic byte[]static byte[]randomAESKey(Random random)static byte[]randomBytes(int length)static byte[]randomBytes(Random random, int length)static Stringstatic StringrandomStringAESKey(Random random)static Stringstatic StringrandomStringToken(Random random)static byte[]static byte[]randomToken(Random random)static Stringstatic StringrandomUsername(Random random)static byte[]sign(byte[] bytes, ECPrivateKey privateKey)static StringtoHex(byte[] bytes)static ECPrivateKeytoPrivateECDSAKey(byte[] bytes)static ECPrivateKeytoPrivateECKey(byte[] bytes)Deprecated.static RSAPrivateKeytoPrivateRSAKey(byte[] bytes)static ECPublicKeytoPublicECDSAKey(byte[] bytes)static ECPublicKeytoPublicECKey(byte[] bytes)Deprecated.static RSAPublicKeytoPublicRSAKey(byte[] bytes)static voidverifySign(byte[] bytes, byte[] sign, ECPublicKey publicKey)static voidverifySign(byte[] bytes, byte[] sign, RSAPublicKey publicKey)static voidverifySign(InputStream input, byte[] sign, ECPublicKey publicKey)static voidverifySign(InputStream input, byte[] sign, RSAPublicKey publicKey)static StringverifyToken(String token)
-
Field Details
-
EC_ALGO
- See Also:
- Constant Field Values
-
EC_CURVE
- See Also:
- Constant Field Values
-
EC_SIGN_ALGO
- See Also:
- Constant Field Values
-
TOKEN_LENGTH
public static final int TOKEN_LENGTH- See Also:
- Constant Field Values
-
RSA_ALGO
- See Also:
- Constant Field Values
-
RSA_SIGN_ALGO
- See Also:
- Constant Field Values
-
RSA_CIPHER_ALGO
- 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
- See Also:
- Constant Field Values
-
NUMBERS
public static final byte[] NUMBERS -
secureRandom
-
-
Method Details
-
digest
-
digest
public static byte[] digest(SecurityHelper.DigestAlgorithm algo, InputStream input) throws IOException- Throws:
IOException
-
digest
- Throws:
IOException
-
digest
-
digest
- Throws:
IOException
-
genECKeyPair
Deprecated. -
genECDSAKeyPair
-
genRSAKeyPair
-
isValidSign
public static boolean isValidSign(byte[] bytes, byte[] sign, ECPublicKey publicKey) throws SignatureException- Throws:
SignatureException
-
isValidSign
public static boolean isValidSign(InputStream input, byte[] sign, ECPublicKey publicKey) throws IOException, SignatureException- Throws:
IOExceptionSignatureException
-
isValidSign
public static boolean isValidSign(byte[] bytes, byte[] sign, RSAPublicKey publicKey) throws SignatureException- Throws:
SignatureException
-
isValidSign
public static boolean isValidSign(InputStream input, byte[] sign, RSAPublicKey publicKey) throws IOException, SignatureException- Throws:
IOExceptionSignatureException
-
isValidToken
-
newCipher
-
newDigest
-
newRandom
-
newECSignSignature
-
newRSASignSignature
-
newECVerifySignature
-
newRSAVerifySignature
-
randomBytes
public static byte[] randomBytes(int length) -
randomBytes
-
randomStringToken
-
randomStringToken
-
randomToken
public static byte[] randomToken() -
randomToken
-
randomStringAESKey
-
randomStringAESKey
-
randomAESKey
public static byte[] randomAESKey() -
randomAESKey
-
randomUsername
-
randomUsername
-
sign
-
toHex
-
toPublicECKey
Deprecated.- Throws:
InvalidKeySpecException
-
toPrivateECKey
Deprecated.- Throws:
InvalidKeySpecException
-
toPublicECDSAKey
- Throws:
InvalidKeySpecException
-
toPrivateECDSAKey
- Throws:
InvalidKeySpecException
-
toPublicRSAKey
- Throws:
InvalidKeySpecException
-
toPrivateRSAKey
- Throws:
InvalidKeySpecException
-
verifySign
public static void verifySign(byte[] bytes, byte[] sign, ECPublicKey publicKey) throws SignatureException- Throws:
SignatureException
-
verifySign
public static void verifySign(InputStream input, byte[] sign, ECPublicKey publicKey) throws SignatureException, IOException- Throws:
SignatureExceptionIOException
-
verifySign
public static void verifySign(byte[] bytes, byte[] sign, RSAPublicKey publicKey) throws SignatureException- Throws:
SignatureException
-
verifySign
public static void verifySign(InputStream input, byte[] sign, RSAPublicKey publicKey) throws SignatureException, IOException- Throws:
SignatureExceptionIOException
-
verifyToken
-
newRSADecryptCipher
-
newRSAEncryptCipher
-
encrypt
- Throws:
Exception
-
encrypt
- Throws:
Exception
-
getAESKey
- Throws:
Exception
-
encrypt
- Throws:
Exception
-
decrypt
- Throws:
Exception
-
decrypt
- Throws:
Exception
-
fromHex
-