public class CryptoFunctions extends Object
Constructor and Description |
---|
CryptoFunctions() |
Modifier and Type | Method and Description |
---|---|
static byte[] |
createXorArray1(String password)
Creates an byte array for xor obfuscation (method 1)
|
static int |
createXorKey1(String password)
Create the xor key for xor obfuscation, which is used to create the xor array (method 1)
|
static int |
createXorVerifier1(String password)
Create the verifier for xor obfuscation (method 1)
|
static int |
createXorVerifier2(String password)
This method generates the xor verifier for word documents < 2007 (method 2).
|
static byte[] |
generateIv(HashAlgorithm hashAlgorithm,
byte[] salt,
byte[] blockKey,
int blockSize)
2.3.4.12 Initialization Vector Generation (Agile Encryption)
Initialization vectors are used in all cases for agile encryption.
|
static byte[] |
generateKey(byte[] passwordHash,
HashAlgorithm hashAlgorithm,
byte[] blockKey,
int keySize)
2.3.4.11 Encryption Key Generation (Agile Encryption)
...
|
static byte[] |
getBlock0(byte[] hash,
int size)
Returns a new byte array with a truncated to the given size.
|
static byte[] |
getBlock36(byte[] hash,
int size)
Returns a new byte array with a truncated to the given size.
|
static Cipher |
getCipher(Key key,
CipherAlgorithm cipherAlgorithm,
ChainingMode chain,
byte[] vec,
int cipherMode,
String padding)
Initialize a new cipher object with the given cipher properties
If the given algorithm is not implemented in the JCE, it will try to load it from the bouncy castle
provider.
|
static Cipher |
getCipher(SecretKey key,
CipherAlgorithm cipherAlgorithm,
ChainingMode chain,
byte[] vec,
int cipherMode) |
static Mac |
getMac(HashAlgorithm hashAlgorithm) |
static MessageDigest |
getMessageDigest(HashAlgorithm hashAlgorithm) |
static byte[] |
hashPassword(String password,
HashAlgorithm hashAlgorithm,
byte[] salt,
int spinCount)
2.3.4.7 ECMA-376 Document Encryption Key Generation (Standard Encryption)
2.3.4.11 Encryption Key Generation (Agile Encryption)
The encryption key for ECMA-376 document encryption [ECMA-376] using agile encryption MUST be
generated by using the following method, which is derived from PKCS #5: Password-Based
Cryptography Version 2.0 [RFC2898].
|
static byte[] |
hashPassword(String password,
HashAlgorithm hashAlgorithm,
byte[] salt,
int spinCount,
boolean iteratorFirst)
Generalized method for read and write protection hash generation.
|
static void |
registerBouncyCastle() |
static String |
xorHashPassword(String password)
This method generates the xored-hashed password for word documents < 2007.
|
static String |
xorHashPasswordReversed(String password)
Convenience function which returns the reversed xored-hashed password for further
processing in word documents 2007 and newer, which utilize a real hashing algorithm like sha1.
|
public static byte[] hashPassword(String password, HashAlgorithm hashAlgorithm, byte[] salt, int spinCount)
generateKey(byte[],HashAlgorithm,byte[],int)
password
- hashAlgorithm
- salt
- spinCount
- public static byte[] hashPassword(String password, HashAlgorithm hashAlgorithm, byte[] salt, int spinCount, boolean iteratorFirst)
password
- hashAlgorithm
- salt
- spinCount
- iteratorFirst
- if true, the iterator is hashed before the n-1 hash value,
if false the n-1 hash value is applied firstpublic static byte[] generateIv(HashAlgorithm hashAlgorithm, byte[] salt, byte[] blockKey, int blockSize)
public static byte[] generateKey(byte[] passwordHash, HashAlgorithm hashAlgorithm, byte[] blockKey, int keySize)
passwordHash
- hashAlgorithm
- blockKey
- keySize
- public static Cipher getCipher(SecretKey key, CipherAlgorithm cipherAlgorithm, ChainingMode chain, byte[] vec, int cipherMode)
public static Cipher getCipher(Key key, CipherAlgorithm cipherAlgorithm, ChainingMode chain, byte[] vec, int cipherMode, String padding)
key
- the secrect keycipherAlgorithm
- the cipher algorithmchain
- the chaining modevec
- the initialization vector (IV), can be nullcipherMode
- Cipher.DECRYPT_MODE or Cipher.ENCRYPT_MODEpadding
- GeneralSecurityException
EncryptedDocumentException
- if the initialization failed or if an algorithm was specified,
which depends on a missing bouncy castle providerpublic static byte[] getBlock36(byte[] hash, int size)
hash
- the to be truncated/filled hash byte arraysize
- the size of the returned byte arraypublic static byte[] getBlock0(byte[] hash, int size)
hash
- the to be truncated/filled hash byte arraysize
- the size of the returned byte arraypublic static MessageDigest getMessageDigest(HashAlgorithm hashAlgorithm)
public static Mac getMac(HashAlgorithm hashAlgorithm)
public static void registerBouncyCastle()
public static int createXorVerifier2(String password)
password
- the passwordpublic static String xorHashPassword(String password)
public static String xorHashPasswordReversed(String password)
public static int createXorVerifier1(String password)
password
- the passwordpublic static int createXorKey1(String password)
password
- the passwordpublic static byte[] createXorArray1(String password)
password
- the passwordCopyright © 2007-2019. All Rights Reserved.