public class EncryptionUtilities extends Object
Modifier and Type | Method and Description |
---|---|
static String |
calculateFileHash(FileChannel ch,
MessageDigest d) |
static String |
calculateHash(MessageDigest d,
byte[] bytes)
Calculate a hash String from the passed in byte[].
|
static String |
calculateMD5Hash(byte[] bytes)
Calculate an MD5 Hash String from the passed in byte[].
|
static String |
calculateSHA1Hash(byte[] bytes)
Calculate an MD5 Hash String from the passed in byte[].
|
static String |
calculateSHA256Hash(byte[] bytes)
Calculate an SHA-256 Hash String from the passed in byte[].
|
static String |
calculateSHA512Hash(byte[] bytes)
Calculate an SHA-512 Hash String from the passed in byte[].
|
static Cipher |
createAesCipher(Key key,
int mode)
Creates a Cipher from the passed in key, using the passed in mode.
|
static Cipher |
createAesCipher(String key,
int mode) |
static Cipher |
createAesDecryptionCipher(String key) |
static Cipher |
createAesEncryptionCipher(String key) |
static byte[] |
createCipherBytes(String key,
int bitsNeeded) |
static String |
decrypt(String key,
String hexStr)
Get unencrypted String from encrypted hex String
|
static byte[] |
decryptBytes(String key,
String hexStr)
Get unencrypted byte[] from encrypted hex String
|
static String |
encrypt(String key,
String content)
Get hex String of content String encrypted.
|
static String |
encryptBytes(String key,
byte[] content) |
static String |
fastMD5(File file)
Super-fast MD5 calculation from entire file.
|
static String |
fastSHA1(File file)
Super-fast SHA-1 calculation from entire file.
|
static String |
fastSHA256(File file)
Super-fast SHA-256 calculation from entire file.
|
static String |
fastSHA512(File file)
Super-fast SHA-512 calculation from entire file.
|
static MessageDigest |
getDigest(String digest) |
static MessageDigest |
getMD5Digest() |
static MessageDigest |
getSHA1Digest() |
static MessageDigest |
getSHA256Digest() |
static MessageDigest |
getSHA512Digest() |
public static String fastMD5(File file)
file
- File that from which to compute the MD5public static String fastSHA1(File file)
file
- File that from which to compute the SHA-1public static String fastSHA256(File file)
file
- File that from which to compute the SHA-256public static String fastSHA512(File file)
file
- File that from which to compute the SHA-512public static String calculateFileHash(FileChannel ch, MessageDigest d) throws IOException
IOException
public static String calculateMD5Hash(byte[] bytes)
bytes
- byte[] for which to obtain the MD5 hash.public static MessageDigest getDigest(String digest)
public static MessageDigest getMD5Digest()
public static String calculateSHA1Hash(byte[] bytes)
bytes
- byte[] of bytes for which to compute the SHA1public static MessageDigest getSHA1Digest()
public static String calculateSHA256Hash(byte[] bytes)
bytes
- byte[] for which to compute the SHA-2 (SHA-256)public static MessageDigest getSHA256Digest()
public static String calculateSHA512Hash(byte[] bytes)
bytes
- byte[] for which to compute the SHA-3 (SHA-512)public static MessageDigest getSHA512Digest()
public static byte[] createCipherBytes(String key, int bitsNeeded)
public static Cipher createAesEncryptionCipher(String key) throws Exception
Exception
public static Cipher createAesDecryptionCipher(String key) throws Exception
Exception
public static Cipher createAesCipher(String key, int mode) throws Exception
Exception
public static Cipher createAesCipher(Key key, int mode) throws Exception
key
- SecretKeySpecmode
- Cipher.ENCRYPT_MODE or Cipher.DECRYPT_MODEException
- if the requested Cipher instance does not exist.public static String encrypt(String key, String content)
key
- String value of the encryption key (passphrase)content
- String value of the content to be encrypted using the passed in encryption keypublic static String decrypt(String key, String hexStr)
key
- String encryption key that was used to encryption the passed in hexStr of characters.hexStr
- String encrypted bytes (as a HEX string)public static byte[] decryptBytes(String key, String hexStr)
key
- String encryption/decryption keyhexStr
- String of HEX bytes that were encrypted with an encryption keypublic static String calculateHash(MessageDigest d, byte[] bytes)
d
- MessageDigest to update with the passed in bytesbytes
- byte[] of bytes to hashCopyright © 2024. All rights reserved.