public class FileEncryptor
extends java.lang.Object
Class for encrypting and decrypting files.
Constructor and Description |
---|
FileEncryptor()
Constructs a default AES
FileEncryptor instance using a randomly generated key. |
FileEncryptor(Encryptor encryptor)
Constructs a default
FileEncryptor instance using the given Encryptor . |
FileEncryptor(java.security.Key key)
Constructs a default AES
FileEncryptor instance using the given AES key. |
FileEncryptor(java.lang.String password)
Constructs a default AES
FileEncryptor instance using the given password. |
Modifier and Type | Method and Description |
---|---|
void |
decrypt(java.io.File src,
java.io.File dest)
Reads and decrypts file
src and writes the decrypted result to file dest . |
void |
encrypt(java.io.File src,
java.io.File dest)
Reads and encrypts file
src and writes the encrypted result to file dest . |
int |
getBufferSize()
Returns the buffer size.
|
Encryptor |
getEncryptor()
Returns the encryptor.
|
static void |
main(java.lang.String[] args) |
void |
setBufferSize(int bufferSize)
Sets the buffer size.
|
public FileEncryptor()
Constructs a default AES FileEncryptor
instance using a randomly generated key. Obtain the key by calling getEncryptor()
and Encryptor.getKey()
.
public FileEncryptor(java.lang.String password)
Constructs a default AES FileEncryptor
instance using the given password.
password
- the password used for encryption/decryptionpublic FileEncryptor(java.security.Key key)
Constructs a default AES FileEncryptor
instance using the given AES key.
key
- the key used for encryption/decryptionpublic FileEncryptor(Encryptor encryptor)
Constructs a default FileEncryptor
instance using the given Encryptor
.
encryptor
- the encryptor used for encryption/decryptionpublic void encrypt(java.io.File src, java.io.File dest) throws java.security.GeneralSecurityException, java.io.IOException
Reads and encrypts file src
and writes the encrypted result to file dest
.
src
- the source filedest
- the destination filesrc
- dest
- java.io.FileNotFoundException
java.security.GeneralSecurityException
java.io.IOException
public void decrypt(java.io.File src, java.io.File dest) throws java.security.GeneralSecurityException, java.io.IOException
Reads and decrypts file src
and writes the decrypted result to file dest
.
src
- the source filedest
- the destination filejava.io.FileNotFoundException
java.security.GeneralSecurityException
java.io.IOException
public Encryptor getEncryptor()
Returns the encryptor.
public int getBufferSize()
Returns the buffer size.
public void setBufferSize(int bufferSize)
Sets the buffer size.
bufferSize
- the buffer sizepublic static void main(java.lang.String[] args)
args
-