|
IAIK CMS/SMIME Toolkit Demo API Documentation
Version 6.1 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdemo.cms.envelopedData.FileEncryptionDemo
public class FileEncryptionDemo
This class shows how to use the CMS PasswordRecipientInfo
type for password based encrypting the contents of
a file (and later decrypting it again) with the CMS EnvelopedDataStream
EnvelopedData} content type.
The contents is encrypted using the AES cipher. For deriving the key encryption key from the password, the PKCS#5 PBKDF2 key derivation function is used. The content encryption key is decrypted with AES, too.
You can modify this demo to use any other supported algorithm(s). Or you can use it with PBKDF2/AES for encrypting a file simply by calling:
// the file to be encrypted String dataFile = ...; // the file to which to write the encrypted data String encryptedFile = ...; // password char[] password = ...; // encrypt file FileEncryption fe = new FileEncryption(); fe.encrypt(dataFile, encryptedFile, password);Or decrypting a file:
// the encrypted file String encryptedFile = ...; // the file to which to write the decrypted data String decryptedFile = ...; // password char[] password = ...; // decrypt file FileEncryption fe = new FileEncryption(); fe.decrypt(encryptedFile, decryptedFile, password);
EnvelopedDataStream
,
EnvelopedData
,
EnvelopedDataOutputStream
,
PasswordRecipientInfo
Constructor Summary | |
---|---|
FileEncryptionDemo()
Default constructor. |
Method Summary | |
---|---|
void |
decrypt(java.lang.String inFile,
java.lang.String outFile,
char[] password)
Uses the given password to decrypt the contents from inFile
and write the it to outFile . |
void |
encrypt(java.lang.String inFile,
java.lang.String outFile,
char[] password)
Uses the given password to encrypt the contents from inFile
and write the encryption result to outFile . |
static void |
main(java.lang.String[] argv)
Main method. |
void |
start()
Starts the demo. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FileEncryptionDemo()
Method Detail |
---|
public void encrypt(java.lang.String inFile, java.lang.String outFile, char[] password) throws java.lang.Exception
inFile
and write the encryption result to outFile
.
The contents is encrypted using the AES cipher. For dereiving the key
encryption key from the password, the PKCS#5 PBKDF2 key derivation function
is used. The content encryption key is decrypted with AES, too.
inFile
- the file from which to read the encrypted (enveloped) dataoutFile
- the file to which to write the decrypted datapassword
- the password to be used for decryption
java.lang.Exception
- if an error occurspublic void decrypt(java.lang.String inFile, java.lang.String outFile, char[] password) throws java.lang.Exception
inFile
and write the it to outFile
.
inFile
- the file from which to read the encrypted (enveloped) dataoutFile
- the file to which to write the decrypted datapassword
- the password to be used for decryption
java.lang.Exception
- if an error occurspublic void start()
public static void main(java.lang.String[] argv) throws java.lang.Exception
java.lang.Exception
- if some error occurs
|
IAIK CMS/SMIME Toolkit Demo API Documentation
Version 6.1 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
![]() |
v6.1 (c) 2002 IAIK, (c) 2003 - 2025 SIC |
![]() |