public class DeEncrypter
extends java.lang.Object
Some terminology:
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
PBEAlgorhythm |
Constructor and Description |
---|
DeEncrypter()
Parameterless Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
configureAES(java.lang.String pass) |
boolean |
configurePBE(java.lang.String pass)
Configure a password (or PIN) based en/decryption.
|
java.lang.String |
decrypt(java.lang.String ciphertext)
Decrypt a given string (DE: Entschluesselt eine Zeichenkette, welche mit
der Methode encrypt verschluesselt wurde).
|
void |
decryptFile(java.lang.String encryptedSrcFile,
java.lang.String decryptedDstFile)
Symetric decryption of given encrypted file.
|
void |
decryptInputStream(java.io.InputStream encryptedInpStream,
java.io.OutputStream decryptedOutStream)
Symetric decryption of given encrypted input stream.
|
java.lang.String |
encrypt(java.lang.String str)
Encrypt a string (DE: Verschluesselt Zeichenkette).
|
void |
encryptFile(java.lang.String srcFile,
java.lang.String encryptedDstFile)
Encrypt given file (by path) using the symetric encryption.
|
void |
encryptInputStream(java.io.InputStream inStream,
java.io.OutputStream encryptedOutStream)
Encrypt given input stream using the symetric encryption.
|
java.lang.String |
getCharset() |
javax.crypto.CipherInputStream |
getCipherInputStream(java.io.FileInputStream fis)
Input stream with cipher.
|
javax.crypto.CipherOutputStream |
getCipherOutputStream(java.io.FileOutputStream fos)
Output stream with cipher.
|
javax.crypto.Cipher |
getDecryptionCipher()
Get cipher for decryption.
|
javax.crypto.Cipher |
getEncryptionCipher()
Get cipher instance for encryption based on configuration.
|
java.lang.String |
getErrorMessage()
Returns the last errorMessage.
|
static java.lang.String |
getMD5Password(java.lang.String plainText)
Encrypts a given string into a MD5 hash.
|
javax.crypto.Cipher |
initDecryptionCipher(java.lang.String password,
java.lang.String type)
Initialize DeEncrypter by password (or phrase) and type.
|
javax.crypto.Cipher |
initEncryptionCipher(java.lang.String password,
java.lang.String type) |
boolean |
isAESCipher()
If 'true' the PBE key is usable.
|
boolean |
isPBECipher()
If 'true' the PBE key is usable.
|
void |
loadKey(java.io.File inAESKeyFile,
java.security.PrivateKey pk)
Load the AESKey to decrypt files.
|
void |
saveKey(java.io.File outAESKeyFile,
java.security.PublicKey pk) |
void |
setCharset(java.lang.String charset) |
public static final java.lang.String PBEAlgorhythm
public boolean configurePBE(java.lang.String pass)
pass
- public boolean configureAES(java.lang.String pass)
public java.lang.String getCharset()
public void setCharset(java.lang.String charset)
charset
- the charset to setpublic boolean isPBECipher()
public boolean isAESCipher()
public javax.crypto.Cipher getEncryptionCipher()
public javax.crypto.Cipher getDecryptionCipher()
public javax.crypto.Cipher initDecryptionCipher(java.lang.String password, java.lang.String type)
On AES the password can be blank and will be created then by the
system.
N.B.On system algorithms you have no password. You must use the
generated cipher also for decrypting.
password
- type
- "AES" (password or generated) or "PBE" (password based
encryption)public javax.crypto.Cipher initEncryptionCipher(java.lang.String password, java.lang.String type)
password
- type
- "AES" (password or generated) or "PBE" (password based
encryption)public javax.crypto.CipherInputStream getCipherInputStream(java.io.FileInputStream fis)
fis
- - FileInputStreampublic javax.crypto.CipherOutputStream getCipherOutputStream(java.io.FileOutputStream fos)
fos
- - FileOutputStreampublic java.lang.String encrypt(java.lang.String str) throws java.lang.SecurityException
str
- Plain text to cipher (crypt)java.lang.SecurityException
- Description of the Exceptionpublic java.lang.String decrypt(java.lang.String ciphertext) throws java.lang.SecurityException
ciphertext
- The encrypted string.java.lang.SecurityException
- Description of the Exception.public void encryptFile(java.lang.String srcFile, java.lang.String encryptedDstFile) throws java.security.GeneralSecurityException, java.io.IOException
Symmetric-key encryptionmeans the same key is used to both encrypt and decrypt. It sometimes called secret-key encryption, single-key encryption or simply symmetric encryption.
srcFile
- source file to encryptencryptedDstFile
- the encrypted filejava.security.GeneralSecurityException
java.io.IOException
public void encryptInputStream(java.io.InputStream inStream, java.io.OutputStream encryptedOutStream) throws java.security.GeneralSecurityException, java.io.IOException
Streams werden mit close() geschlossen.
inStream
- encryptedOutStream
- java.security.GeneralSecurityException
java.io.IOException
public void decryptFile(java.lang.String encryptedSrcFile, java.lang.String decryptedDstFile) throws java.security.GeneralSecurityException, java.io.IOException
Use configureAES(java.lang.String)
to configure the processor.
encryptedSrcFile
- decryptedDstFile
- java.security.GeneralSecurityException
java.io.IOException
public void decryptInputStream(java.io.InputStream encryptedInpStream, java.io.OutputStream decryptedOutStream) throws java.security.GeneralSecurityException, java.io.IOException
Use configureAES(java.lang.String)
to configure the processor.
Streams werden mit close() geschlossen.
java.security.GeneralSecurityException
java.io.IOException
public static java.lang.String getMD5Password(java.lang.String plainText) throws java.security.NoSuchAlgorithmException
plainText
- string to encryptjava.security.NoSuchAlgorithmException
- possible exceptionpublic void saveKey(java.io.File outAESKeyFile, java.security.PublicKey pk) throws java.io.IOException, java.security.GeneralSecurityException
java.io.IOException
java.security.GeneralSecurityException
public void loadKey(java.io.File inAESKeyFile, java.security.PrivateKey pk) throws java.security.GeneralSecurityException, java.io.IOException
inAESKeyFile
- pk
- java.security.GeneralSecurityException
java.io.IOException
public java.lang.String getErrorMessage()