Package pro.gravit.utils.helper
Class SecurityHelper
java.lang.Object
pro.gravit.utils.helper.SecurityHelper
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final byte[]static final Stringstatic final Stringstatic final intstatic final intstatic final Stringstatic final SecureRandomstatic final intstatic final int -
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 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 byte[]sign(byte[] bytes, RSAPrivateKey privateKey) static StringtoHex(byte[] bytes) static ECPrivateKeytoPrivateECDSAKey(byte[] bytes) static RSAPrivateKeytoPrivateRSAKey(byte[] bytes) static ECPublicKeytoPublicECDSAKey(byte[] bytes) 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:
-
EC_CURVE
- See Also:
-
EC_SIGN_ALGO
- See Also:
-
TOKEN_LENGTH
public static final int TOKEN_LENGTH- See Also:
-
RSA_ALGO
- See Also:
-
RSA_SIGN_ALGO
- See Also:
-
RSA_CIPHER_ALGO
- See Also:
-
AES_KEY_LENGTH
public static final int AES_KEY_LENGTH- See Also:
-
TOKEN_STRING_LENGTH
public static final int TOKEN_STRING_LENGTH- See Also:
-
RSA_KEY_LENGTH_BITS
public static final int RSA_KEY_LENGTH_BITS- See Also:
-
RSA_KEY_LENGTH
public static final int RSA_KEY_LENGTH- See Also:
-
CRYPTO_MAX_LENGTH
public static final int CRYPTO_MAX_LENGTH- See Also:
-
HEX
- See Also:
-
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
-
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
-
sign
-
toHex
-
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
-