public class EncryptionHelper extends Object
Constructor and Description |
---|
EncryptionHelper() |
Modifier and Type | Method and Description |
---|---|
static byte[] |
createCipherBlockChainingVector()
Creates an initialized vector used for Cipher Block Chaining.
|
static <T> T |
decrypt(byte[] encryptedObject,
byte[] key,
Class<T> encryptedClass,
boolean symmetric)
Decrypts a ByteArray into an Object of type T.
|
static <T> T |
decrypt(com.google.protobuf.ByteString encryptedObject,
byte[] key,
Class<T> encryptedClass,
boolean symmetric)
Decrypts a ByteString into an Object of type T.
|
static <T> T |
decryptAsymmetric(com.google.protobuf.ByteString encryptedObject,
byte[] key,
Class<T> encryptedClass)
Decrypt an object using an asymmetric key and directly cast it to type T.
|
static <T> T |
decryptSymmetric(com.google.protobuf.ByteString encryptedObject,
byte[] key,
Class<T> encryptedClass)
Decrypt an object with a symmetric key and directly cast it to type T.
|
static byte[] |
encrypt(Serializable object,
byte[] key,
boolean symmetric)
Encrypts any Object into a ByteString.
|
static com.google.protobuf.ByteString |
encryptAsymmetric(Serializable object,
byte[] key)
Encrypts any Object into a ByteString using a symmetric key
|
static com.google.protobuf.ByteString |
encryptSymmetric(Serializable object,
byte[] key)
Encrypts any Object into a ByteString using a symmetric key.
|
static byte[] |
generateKey()
Generate a key with given transformation and key length which can then be used
for symmetric en- or decryption.
|
static KeyPair |
generateKeyPair()
Generate a key pair given transformation and key length which can then be used
for asymmetric en- or decryption.
|
static byte[] |
hash(String string)
Hashes a string that has to be UTF-8 encoeded symmetrically.
|
public static byte[] generateKey()
public static KeyPair generateKeyPair()
public static byte[] hash(String string)
string
- String to be hashedpublic static com.google.protobuf.ByteString encryptSymmetric(Serializable object, byte[] key) throws IOException
object
- Object to be encryptedkey
- byte[] to encrypt object withIOException
- Any IO error occurring during the serialization and
encryption.public static com.google.protobuf.ByteString encryptAsymmetric(Serializable object, byte[] key) throws IOException
object
- Object to be encryptedkey
- byte[] to encrypt object withIOException
- Any IO error occurring during the serialization and
encryption.public static byte[] encrypt(Serializable object, byte[] key, boolean symmetric) throws IOException
object
- Object to be encryptedkey
- byte[] to encrypt object withsymmetric
- if the encryption should use a symmetric or asymmetric keyIOException
- Any IO error occurring during the serialization and
encryption.public static <T> T decryptSymmetric(com.google.protobuf.ByteString encryptedObject, byte[] key, Class<T> encryptedClass) throws IOException, BadPaddingException
T
- the type to which the encrypted object is castedencryptedObject
- the object encrypted as a ByteStringkey
- the key used to decrypt the objectencryptedClass
- the class to which the decrypted object is castIOException
- if the encrypted data is corruptedBadPaddingException
- if the wrong key is used for decryptionClassCastException
- if the encrypted object can not be cast to Tpublic static <T> T decryptAsymmetric(com.google.protobuf.ByteString encryptedObject, byte[] key, Class<T> encryptedClass) throws IOException, BadPaddingException
T
- the type to which the encrypted object is castedencryptedObject
- the object encrypted as a ByteStringkey
- the key used to decrypt the objectencryptedClass
- the class to which the decrypted object is castIOException
- if the encrypted data is corruptedBadPaddingException
- if the wrong key is used for decryptionClassCastException
- if the encrypted object can not be cast to Tpublic static <T> T decrypt(com.google.protobuf.ByteString encryptedObject, byte[] key, Class<T> encryptedClass, boolean symmetric) throws IOException, BadPaddingException, ClassCastException
T
- the type to which the encrypted object is castedencryptedObject
- ByteString to be decryptedkey
- byte[] to decrypt the encrypted object withencryptedClass
- the class to which the decrypted object is castsymmetric
- if the key is symmetric or asymmetricBadPaddingException
- if a wrong key is usedIOException
- if corrupted dataClassCastException
- if the encrypted object can not be cast to Tpublic static <T> T decrypt(byte[] encryptedObject, byte[] key, Class<T> encryptedClass, boolean symmetric) throws IOException, BadPaddingException, ClassCastException
T
- the type to which the encrypted object is castedencryptedObject
- ByteString to be decryptedkey
- byte[] to decrypt the encrypted object withencryptedClass
- the class to which the decrypted object is castsymmetric
- if the key is symmetric or asymmetricBadPaddingException
- if a wrong key is usedIOException
- if corrupted dataClassCastException
- if the encrypted object can not be cast to Tpublic static byte[] createCipherBlockChainingVector()
Copyright © 2017–2018 openbase.org. All rights reserved.