steps towards symmetric file encryption

This commit is contained in:
Thialfihar
2010-04-23 00:01:59 +00:00
parent 78193007b2
commit ab6c884bdf
6 changed files with 158 additions and 17 deletions

View File

@@ -1147,11 +1147,17 @@ public class Apg {
boolean armored,
long encryptionKeyIds[], long signatureKeyId,
String signaturePassPhrase,
ProgressDialogUpdater progress)
ProgressDialogUpdater progress,
int symmetricAlgorithm,
String passPhrase)
throws IOException, GeneralException, PGPException, NoSuchProviderException,
NoSuchAlgorithmException, SignatureException {
Security.addProvider(new BouncyCastleProvider());
if (encryptionKeyIds == null) {
encryptionKeyIds = new long[0];
}
ArmoredOutputStream armorOut = null;
OutputStream out = null;
OutputStream encryptOut = null;
@@ -1166,8 +1172,8 @@ public class Apg {
PGPSecretKeyRing signingKeyRing = null;
PGPPrivateKey signaturePrivateKey = null;
if (encryptionKeyIds == null || encryptionKeyIds.length == 0) {
throw new GeneralException("no encryption key(s) given");
if (encryptionKeyIds.length == 0 && passPhrase == null) {
throw new GeneralException("no encryption key(s) or pass phrase given");
}
if (signatureKeyId != 0) {
@@ -1199,9 +1205,13 @@ public class Apg {
progress.setProgress("preparing streams...", 20, 100);
// encryptFile and compress input file content
PGPEncryptedDataGenerator cPk =
new PGPEncryptedDataGenerator(PGPEncryptedData.AES_256, true, new SecureRandom(),
new PGPEncryptedDataGenerator(symmetricAlgorithm, true, new SecureRandom(),
new BouncyCastleProvider());
if (encryptionKeyIds.length == 0) {
// symmetric encryption
cPk.addMethod(passPhrase.toCharArray());
}
for (int i = 0; i < encryptionKeyIds.length; ++i) {
PGPPublicKey key = getEncryptPublicKey(encryptionKeyIds[i]);
if (key != null) {