mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 11:12:15 -05:00
replaced error and progress strings in APG.java with resource IDs as well
This commit is contained in:
parent
b527ae8b6d
commit
c0d24306cb
@ -174,12 +174,57 @@
|
|||||||
<string name="error_accountNotFound">account '%s' not found</string>
|
<string name="error_accountNotFound">account '%s' not found</string>
|
||||||
<string name="error_addingAccountFailed">adding account '%s' failed</string>
|
<string name="error_addingAccountFailed">adding account '%s' failed</string>
|
||||||
<string name="error_invalidEmail">invalid email '%s'</string>
|
<string name="error_invalidEmail">invalid email '%s'</string>
|
||||||
|
<string name="error_keySizeMinimum512bit">key size must be at least 512bit</string>
|
||||||
|
<string name="error_masterKeyMustNotBeElGamal">the master key cannot be an ElGamal key</string>
|
||||||
|
<string name="error_unknownAlgorithmChoice">unknown algorithm choice</string>
|
||||||
|
<string name="error_userIdNeedsAName">you need to specify a name</string>
|
||||||
|
<string name="error_userIdNeedsAnEmailAddress">you need to specify an email address</string>
|
||||||
|
<string name="error_keyNeedsAUserId">need at least one user id</string>
|
||||||
|
<string name="error_mainUserIdMustNotBeEmpty">main user id must not be empty</string>
|
||||||
|
<string name="error_keyNeedsMasterKey">need at least a master key</string>
|
||||||
|
<string name="error_expiryMustComeAfterCreation">expiry date must come after creation date</string>
|
||||||
|
<string name="error_noEncryptionKeysOrPassPhrase">no encryption key(s) or pass phrase given</string>
|
||||||
|
<string name="error_signatureFailed">signature failed</string>
|
||||||
|
<string name="error_noSignaturePassPhrase">no pass phrase given</string>
|
||||||
|
<string name="error_noSignatureKey">no signature key given</string>
|
||||||
|
<string name="error_invalidData">not valid encryption data</string>
|
||||||
|
<string name="error_corruptData">corrupt data</string>
|
||||||
|
<string name="error_noSymmetricEncryptionPacket">couldn't find a packet with symmetric encryption</string>
|
||||||
|
<string name="error_wrongPassPhrase">wrong pass phrase</string>
|
||||||
|
<string name="error_savingKeys">error saving some key(s)</string>
|
||||||
|
|
||||||
<!-- progress_lowerCase: lowercase, phrases, usually ending in '...' -->
|
<!-- progress_lowerCase: lowercase, phrases, usually ending in '...' -->
|
||||||
|
<string name="progress_done">done.</string>
|
||||||
<string name="progress_initializing">initializing...</string>
|
<string name="progress_initializing">initializing...</string>
|
||||||
<string name="progress_saving">saving...</string>
|
<string name="progress_saving">saving...</string>
|
||||||
<string name="progress_importing">importing...</string>
|
<string name="progress_importing">importing...</string>
|
||||||
<string name="progress_exporting">exporting...</string>
|
<string name="progress_exporting">exporting...</string>
|
||||||
<string name="progress_generating">generating key, this can take a while...</string>
|
<string name="progress_generating">generating key, this can take a while...</string>
|
||||||
|
<string name="progress_buildingKey">building key...</string>
|
||||||
|
<string name="progress_preparingMasterKey">preparing master key...</string>
|
||||||
|
<string name="progress_certifyingMasterKey">certifying master key...</string>
|
||||||
|
<string name="progress_buildingMasterKeyRing">building master key ring...</string>
|
||||||
|
<string name="progress_addingSubKeys">adding sub keys...</string>
|
||||||
|
<string name="progress_savingKeyRing">saving key ring...</string>
|
||||||
|
<string name="progress_importingSecretKeys">importing secret keys...</string>
|
||||||
|
<string name="progress_importingPublicKeys">importing public keys...</string>
|
||||||
|
<string name="progress_reloadingKeys">reloading keys...</string>
|
||||||
|
<string name="progress_exportingKey">exporting key...</string>
|
||||||
|
<string name="progress_exportingKeys">exporting keys...</string>
|
||||||
|
<string name="progress_extractingSignatureKey">extracting signature key...</string>
|
||||||
|
<string name="progress_extractingKey">extracting key...</string>
|
||||||
|
<string name="progress_preparingStreams">preparing streams...</string>
|
||||||
|
<string name="progress_encrypting">encrypting data...</string>
|
||||||
|
<string name="progress_decrypting">decrypting data...</string>
|
||||||
|
<string name="progress_preparingSignature">preparing signature...</string>
|
||||||
|
<string name="progress_generatingSignature">generating signature...</string>
|
||||||
|
<string name="progress_processingSignature">processing signature...</string>
|
||||||
|
<string name="progress_verifyingSignature">verifying signature...</string>
|
||||||
|
<string name="progress_signing">signing...</string>
|
||||||
|
<string name="progress_readingData">reading data...</string>
|
||||||
|
<string name="progress_findingKey">finding key...</string>
|
||||||
|
<string name="progress_decompressingData">decompressing data...</string>
|
||||||
|
<string name="progress_verifyingIntegrity">verifying integrity...</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
||||||
|
@ -279,13 +279,14 @@ public class Apg {
|
|||||||
return mPassPhrase;
|
return mPassPhrase;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PGPSecretKey createKey(int algorithmChoice, int keySize, String passPhrase,
|
public static PGPSecretKey createKey(Context context,
|
||||||
|
int algorithmChoice, int keySize, String passPhrase,
|
||||||
PGPSecretKey masterKey)
|
PGPSecretKey masterKey)
|
||||||
throws NoSuchAlgorithmException, PGPException, NoSuchProviderException,
|
throws NoSuchAlgorithmException, PGPException, NoSuchProviderException,
|
||||||
GeneralException, InvalidAlgorithmParameterException {
|
GeneralException, InvalidAlgorithmParameterException {
|
||||||
|
|
||||||
if (keySize < 512) {
|
if (keySize < 512) {
|
||||||
throw new GeneralException("key size must be at least 512bit");
|
throw new GeneralException(context.getString(R.string.error_keySizeMinimum512bit));
|
||||||
}
|
}
|
||||||
|
|
||||||
Security.addProvider(new BouncyCastleProvider());
|
Security.addProvider(new BouncyCastleProvider());
|
||||||
@ -307,7 +308,7 @@ public class Apg {
|
|||||||
|
|
||||||
case Id.choice.algorithm.elgamal: {
|
case Id.choice.algorithm.elgamal: {
|
||||||
if (masterKey == null) {
|
if (masterKey == null) {
|
||||||
throw new GeneralException("The master key cannot be an ElGamal key.");
|
throw new GeneralException(context.getString(R.string.error_masterKeyMustNotBeElGamal));
|
||||||
}
|
}
|
||||||
keyGen = KeyPairGenerator.getInstance("ELGAMAL", new BouncyCastleProvider());
|
keyGen = KeyPairGenerator.getInstance("ELGAMAL", new BouncyCastleProvider());
|
||||||
BigInteger p = Primes.getBestPrime(keySize);
|
BigInteger p = Primes.getBestPrime(keySize);
|
||||||
@ -329,7 +330,7 @@ public class Apg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
throw new GeneralException("unknown algorithm choice");
|
throw new GeneralException(context.getString(R.string.error_unknownAlgorithmChoice));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -391,7 +392,7 @@ public class Apg {
|
|||||||
throws Apg.GeneralException, NoSuchProviderException, PGPException,
|
throws Apg.GeneralException, NoSuchProviderException, PGPException,
|
||||||
NoSuchAlgorithmException, SignatureException {
|
NoSuchAlgorithmException, SignatureException {
|
||||||
|
|
||||||
progress.setProgress("building key...", 0, 100);
|
progress.setProgress(R.string.progress_buildingKey, 0, 100);
|
||||||
|
|
||||||
Security.addProvider(new BouncyCastleProvider());
|
Security.addProvider(new BouncyCastleProvider());
|
||||||
|
|
||||||
@ -416,9 +417,9 @@ public class Apg {
|
|||||||
try {
|
try {
|
||||||
userId = editor.getValue();
|
userId = editor.getValue();
|
||||||
} catch (UserIdEditor.NoNameException e) {
|
} catch (UserIdEditor.NoNameException e) {
|
||||||
throw new Apg.GeneralException("you need to specify a name");
|
throw new Apg.GeneralException(context.getString(R.string.error_userIdNeedsAName));
|
||||||
} catch (UserIdEditor.NoEmailException e) {
|
} catch (UserIdEditor.NoEmailException e) {
|
||||||
throw new Apg.GeneralException("you need to specify an email");
|
throw new Apg.GeneralException(context.getString(R.string.error_userIdNeedsAnEmailAddress));
|
||||||
} catch (UserIdEditor.InvalidEmailException e) {
|
} catch (UserIdEditor.InvalidEmailException e) {
|
||||||
throw new Apg.GeneralException(e.getMessage());
|
throw new Apg.GeneralException(e.getMessage());
|
||||||
}
|
}
|
||||||
@ -436,15 +437,15 @@ public class Apg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (userIds.size() == 0) {
|
if (userIds.size() == 0) {
|
||||||
throw new Apg.GeneralException("need at least one user id");
|
throw new Apg.GeneralException(context.getString(R.string.error_keyNeedsAUserId));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gotMainUserId) {
|
if (!gotMainUserId) {
|
||||||
throw new Apg.GeneralException("main user id can't be empty");
|
throw new Apg.GeneralException(context.getString(R.string.error_mainUserIdMustNotBeEmpty));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keyEditors.getChildCount() == 0) {
|
if (keyEditors.getChildCount() == 0) {
|
||||||
throw new Apg.GeneralException("need at least a main key");
|
throw new Apg.GeneralException(context.getString(R.string.error_keyNeedsMasterKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < keyEditors.getChildCount(); ++i) {
|
for (int i = 0; i < keyEditors.getChildCount(); ++i) {
|
||||||
@ -452,7 +453,7 @@ public class Apg {
|
|||||||
keys.add(editor.getValue());
|
keys.add(editor.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
progress.setProgress("preparing master key...", 10, 100);
|
progress.setProgress(R.string.progress_preparingMasterKey, 10, 100);
|
||||||
KeyEditor keyEditor = (KeyEditor) keyEditors.getChildAt(0);
|
KeyEditor keyEditor = (KeyEditor) keyEditors.getChildAt(0);
|
||||||
int usageId = keyEditor.getUsage();
|
int usageId = keyEditor.getUsage();
|
||||||
boolean canSign = (usageId == Id.choice.usage.sign_only ||
|
boolean canSign = (usageId == Id.choice.usage.sign_only ||
|
||||||
@ -472,7 +473,7 @@ public class Apg {
|
|||||||
masterKey.extractPrivateKey(oldPassPhrase.toCharArray(),
|
masterKey.extractPrivateKey(oldPassPhrase.toCharArray(),
|
||||||
new BouncyCastleProvider());
|
new BouncyCastleProvider());
|
||||||
|
|
||||||
progress.setProgress("certifying master key...", 20, 100);
|
progress.setProgress(R.string.progress_certifyingMasterKey, 20, 100);
|
||||||
for (int i = 0; i < userIds.size(); ++i) {
|
for (int i = 0; i < userIds.size(); ++i) {
|
||||||
String userId = userIds.get(i);
|
String userId = userIds.get(i);
|
||||||
|
|
||||||
@ -510,12 +511,12 @@ public class Apg {
|
|||||||
GregorianCalendar expiryDate = keyEditor.getExpiryDate();
|
GregorianCalendar expiryDate = keyEditor.getExpiryDate();
|
||||||
long numDays = getNumDatesBetween(creationDate, expiryDate);
|
long numDays = getNumDatesBetween(creationDate, expiryDate);
|
||||||
if (numDays <= 0) {
|
if (numDays <= 0) {
|
||||||
throw new GeneralException("expiry date must be later than creation date");
|
throw new GeneralException(context.getString(R.string.error_expiryMustComeAfterCreation));
|
||||||
}
|
}
|
||||||
hashedPacketsGen.setKeyExpirationTime(true, numDays * 86400);
|
hashedPacketsGen.setKeyExpirationTime(true, numDays * 86400);
|
||||||
}
|
}
|
||||||
|
|
||||||
progress.setProgress("building master key ring...", 30, 100);
|
progress.setProgress(R.string.progress_buildingMasterKeyRing, 30, 100);
|
||||||
PGPKeyRingGenerator keyGen =
|
PGPKeyRingGenerator keyGen =
|
||||||
new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION,
|
new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION,
|
||||||
masterKeyPair, mainUserId,
|
masterKeyPair, mainUserId,
|
||||||
@ -523,7 +524,7 @@ public class Apg {
|
|||||||
hashedPacketsGen.generate(), unhashedPacketsGen.generate(),
|
hashedPacketsGen.generate(), unhashedPacketsGen.generate(),
|
||||||
new SecureRandom(), new BouncyCastleProvider().getName());
|
new SecureRandom(), new BouncyCastleProvider().getName());
|
||||||
|
|
||||||
progress.setProgress("adding sub keys...", 40, 100);
|
progress.setProgress(R.string.progress_addingSubKeys, 40, 100);
|
||||||
for (int i = 1; i < keys.size(); ++i) {
|
for (int i = 1; i < keys.size(); ++i) {
|
||||||
progress.setProgress(40 + 50 * (i - 1)/ (keys.size() - 1), 100);
|
progress.setProgress(40 + 50 * (i - 1)/ (keys.size() - 1), 100);
|
||||||
PGPSecretKey subKey = keys.get(i);
|
PGPSecretKey subKey = keys.get(i);
|
||||||
@ -561,7 +562,7 @@ public class Apg {
|
|||||||
GregorianCalendar expiryDate = keyEditor.getExpiryDate();
|
GregorianCalendar expiryDate = keyEditor.getExpiryDate();
|
||||||
long numDays = getNumDatesBetween(creationDate, expiryDate);
|
long numDays = getNumDatesBetween(creationDate, expiryDate);
|
||||||
if (numDays <= 0) {
|
if (numDays <= 0) {
|
||||||
throw new GeneralException("expiry date must be later than creation date");
|
throw new GeneralException(context.getString(R.string.error_expiryMustComeAfterCreation));
|
||||||
}
|
}
|
||||||
hashedPacketsGen.setKeyExpirationTime(true, numDays * 86400);
|
hashedPacketsGen.setKeyExpirationTime(true, numDays * 86400);
|
||||||
}
|
}
|
||||||
@ -573,13 +574,13 @@ public class Apg {
|
|||||||
PGPSecretKeyRing secretKeyRing = keyGen.generateSecretKeyRing();
|
PGPSecretKeyRing secretKeyRing = keyGen.generateSecretKeyRing();
|
||||||
PGPPublicKeyRing publicKeyRing = keyGen.generatePublicKeyRing();
|
PGPPublicKeyRing publicKeyRing = keyGen.generatePublicKeyRing();
|
||||||
|
|
||||||
progress.setProgress("saving key ring...", 90, 100);
|
progress.setProgress(R.string.progress_savingKeyRing, 90, 100);
|
||||||
saveKeyRing(context, secretKeyRing);
|
saveKeyRing(context, secretKeyRing);
|
||||||
saveKeyRing(context, publicKeyRing);
|
saveKeyRing(context, publicKeyRing);
|
||||||
|
|
||||||
loadKeyRings(context, Id.type.public_key);
|
loadKeyRings(context, Id.type.public_key);
|
||||||
loadKeyRings(context, Id.type.secret_key);
|
loadKeyRings(context, Id.type.secret_key);
|
||||||
progress.setProgress("done.", 100, 100);
|
progress.setProgress(R.string.progress_done, 100, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int saveKeyRing(Activity context, PGPPublicKeyRing keyRing) {
|
private static int saveKeyRing(Activity context, PGPPublicKeyRing keyRing) {
|
||||||
@ -649,13 +650,13 @@ public class Apg {
|
|||||||
PGPObjectFactory objectFactory = null;
|
PGPObjectFactory objectFactory = null;
|
||||||
|
|
||||||
if (type == Id.type.secret_key) {
|
if (type == Id.type.secret_key) {
|
||||||
progress.setProgress("importing secret keys...", 0, 100);
|
progress.setProgress(R.string.progress_importingSecretKeys, 0, 100);
|
||||||
} else {
|
} else {
|
||||||
progress.setProgress("importing public keys...", 0, 100);
|
progress.setProgress(R.string.progress_importingPublicKeys, 0, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||||
throw new GeneralException("external storage not ready");
|
throw new GeneralException(context.getString(R.string.error_externalStorageNotReady));
|
||||||
}
|
}
|
||||||
|
|
||||||
FileInputStream fileIn = new FileInputStream(filename);
|
FileInputStream fileIn = new FileInputStream(filename);
|
||||||
@ -693,7 +694,7 @@ public class Apg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (retValue == Id.return_value.error) {
|
if (retValue == Id.return_value.error) {
|
||||||
throw new GeneralException("error saving some key(s)");
|
throw new GeneralException(context.getString(R.string.error_savingKeys));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retValue == Id.return_value.updated) {
|
if (retValue == Id.return_value.updated) {
|
||||||
@ -703,13 +704,13 @@ public class Apg {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
progress.setProgress("reloading keys...", 100, 100);
|
progress.setProgress(R.string.progress_reloadingKeys, 100, 100);
|
||||||
loadKeyRings(context, type);
|
loadKeyRings(context, type);
|
||||||
|
|
||||||
returnData.putInt("added", newKeys);
|
returnData.putInt("added", newKeys);
|
||||||
returnData.putInt("updated", oldKeys);
|
returnData.putInt("updated", oldKeys);
|
||||||
|
|
||||||
progress.setProgress("done.", 100, 100);
|
progress.setProgress(R.string.progress_done, 100, 100);
|
||||||
|
|
||||||
return returnData;
|
return returnData;
|
||||||
}
|
}
|
||||||
@ -720,13 +721,13 @@ public class Apg {
|
|||||||
Bundle returnData = new Bundle();
|
Bundle returnData = new Bundle();
|
||||||
|
|
||||||
if (keys.size() == 1) {
|
if (keys.size() == 1) {
|
||||||
progress.setProgress("exporting key...", 0, 100);
|
progress.setProgress(R.string.progress_exportingKey, 0, 100);
|
||||||
} else {
|
} else {
|
||||||
progress.setProgress("exporting keys...", 0, 100);
|
progress.setProgress(R.string.progress_exportingKeys, 0, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||||
throw new GeneralException("external storage not ready");
|
throw new GeneralException(context.getString(R.string.error_externalStorageNotReady));
|
||||||
}
|
}
|
||||||
FileOutputStream fileOut = new FileOutputStream(new File(filename), false);
|
FileOutputStream fileOut = new FileOutputStream(new File(filename), false);
|
||||||
ArmoredOutputStream out = new ArmoredOutputStream(fileOut);
|
ArmoredOutputStream out = new ArmoredOutputStream(fileOut);
|
||||||
@ -753,7 +754,7 @@ public class Apg {
|
|||||||
fileOut.close();
|
fileOut.close();
|
||||||
returnData.putInt("exported", numKeys);
|
returnData.putInt("exported", numKeys);
|
||||||
|
|
||||||
progress.setProgress("done.", 100, 100);
|
progress.setProgress(R.string.progress_done, 100, 100);
|
||||||
|
|
||||||
return returnData;
|
return returnData;
|
||||||
}
|
}
|
||||||
@ -1196,7 +1197,8 @@ public class Apg {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void encrypt(InputStream inStream, OutputStream outStream,
|
public static void encrypt(Context context,
|
||||||
|
InputStream inStream, OutputStream outStream,
|
||||||
long dataLength,
|
long dataLength,
|
||||||
boolean armored,
|
boolean armored,
|
||||||
long encryptionKeyIds[], long signatureKeyId,
|
long encryptionKeyIds[], long signatureKeyId,
|
||||||
@ -1227,26 +1229,26 @@ public class Apg {
|
|||||||
PGPPrivateKey signaturePrivateKey = null;
|
PGPPrivateKey signaturePrivateKey = null;
|
||||||
|
|
||||||
if (encryptionKeyIds.length == 0 && passPhrase == null) {
|
if (encryptionKeyIds.length == 0 && passPhrase == null) {
|
||||||
throw new GeneralException("no encryption key(s) or pass phrase given");
|
throw new GeneralException(context.getString(R.string.error_noEncryptionKeysOrPassPhrase));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (signatureKeyId != 0) {
|
if (signatureKeyId != 0) {
|
||||||
signingKeyRing = findSecretKeyRing(signatureKeyId);
|
signingKeyRing = findSecretKeyRing(signatureKeyId);
|
||||||
signingKey = getSigningKey(signatureKeyId);
|
signingKey = getSigningKey(signatureKeyId);
|
||||||
if (signingKey == null) {
|
if (signingKey == null) {
|
||||||
throw new GeneralException("signature failed");
|
throw new GeneralException(context.getString(R.string.error_signatureFailed));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (signaturePassPhrase == null) {
|
if (signaturePassPhrase == null) {
|
||||||
throw new GeneralException("no pass phrase given");
|
throw new GeneralException(context.getString(R.string.error_noSignaturePassPhrase));
|
||||||
}
|
}
|
||||||
progress.setProgress("extracting signature key...", 0, 100);
|
progress.setProgress(R.string.progress_extractingSignatureKey, 0, 100);
|
||||||
signaturePrivateKey = signingKey.extractPrivateKey(signaturePassPhrase.toCharArray(),
|
signaturePrivateKey = signingKey.extractPrivateKey(signaturePassPhrase.toCharArray(),
|
||||||
new BouncyCastleProvider());
|
new BouncyCastleProvider());
|
||||||
}
|
}
|
||||||
|
|
||||||
PGPSignatureGenerator signatureGenerator = null;
|
PGPSignatureGenerator signatureGenerator = null;
|
||||||
progress.setProgress("preparing streams...", 5, 100);
|
progress.setProgress(R.string.progress_preparingStreams, 5, 100);
|
||||||
// encryptFile and compress input file content
|
// encryptFile and compress input file content
|
||||||
PGPEncryptedDataGenerator cPk =
|
PGPEncryptedDataGenerator cPk =
|
||||||
new PGPEncryptedDataGenerator(symmetricAlgorithm, true, new SecureRandom(),
|
new PGPEncryptedDataGenerator(symmetricAlgorithm, true, new SecureRandom(),
|
||||||
@ -1265,7 +1267,7 @@ public class Apg {
|
|||||||
encryptOut = cPk.open(out, new byte[1 << 16]);
|
encryptOut = cPk.open(out, new byte[1 << 16]);
|
||||||
|
|
||||||
if (signatureKeyId != 0) {
|
if (signatureKeyId != 0) {
|
||||||
progress.setProgress("preparing signature...", 10, 100);
|
progress.setProgress(R.string.progress_preparingSignature, 10, 100);
|
||||||
signatureGenerator =
|
signatureGenerator =
|
||||||
new PGPSignatureGenerator(signingKey.getPublicKey().getAlgorithm(),
|
new PGPSignatureGenerator(signingKey.getPublicKey().getAlgorithm(),
|
||||||
hashAlgorithm,
|
hashAlgorithm,
|
||||||
@ -1290,7 +1292,7 @@ public class Apg {
|
|||||||
OutputStream pOut = literalGen.open(bcpgOut, PGPLiteralData.BINARY, "",
|
OutputStream pOut = literalGen.open(bcpgOut, PGPLiteralData.BINARY, "",
|
||||||
new Date(), new byte[1 << 16]);
|
new Date(), new byte[1 << 16]);
|
||||||
|
|
||||||
progress.setProgress("encrypting...", 20, 100);
|
progress.setProgress(R.string.progress_encrypting, 20, 100);
|
||||||
long done = 0;
|
long done = 0;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
byte[] buffer = new byte[1 << 16];
|
byte[] buffer = new byte[1 << 16];
|
||||||
@ -1308,7 +1310,7 @@ public class Apg {
|
|||||||
literalGen.close();
|
literalGen.close();
|
||||||
|
|
||||||
if (signatureKeyId != 0) {
|
if (signatureKeyId != 0) {
|
||||||
progress.setProgress("generating signature...", 95, 100);
|
progress.setProgress(R.string.progress_generatingSignature, 95, 100);
|
||||||
signatureGenerator.generate().encode(pOut);
|
signatureGenerator.generate().encode(pOut);
|
||||||
}
|
}
|
||||||
compressGen.close();
|
compressGen.close();
|
||||||
@ -1317,10 +1319,11 @@ public class Apg {
|
|||||||
armorOut.close();
|
armorOut.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
progress.setProgress("done.", 100, 100);
|
progress.setProgress(R.string.progress_done, 100, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void signText(InputStream inStream, OutputStream outStream,
|
public static void signText(Context context,
|
||||||
|
InputStream inStream, OutputStream outStream,
|
||||||
long signatureKeyId, String signaturePassPhrase,
|
long signatureKeyId, String signaturePassPhrase,
|
||||||
int hashAlgorithm,
|
int hashAlgorithm,
|
||||||
ProgressDialogUpdater progress)
|
ProgressDialogUpdater progress)
|
||||||
@ -1336,26 +1339,26 @@ public class Apg {
|
|||||||
PGPPrivateKey signaturePrivateKey = null;
|
PGPPrivateKey signaturePrivateKey = null;
|
||||||
|
|
||||||
if (signatureKeyId == 0) {
|
if (signatureKeyId == 0) {
|
||||||
throw new GeneralException("no signature key given");
|
throw new GeneralException(context.getString(R.string.error_noSignatureKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
signingKeyRing = findSecretKeyRing(signatureKeyId);
|
signingKeyRing = findSecretKeyRing(signatureKeyId);
|
||||||
signingKey = getSigningKey(signatureKeyId);
|
signingKey = getSigningKey(signatureKeyId);
|
||||||
if (signingKey == null) {
|
if (signingKey == null) {
|
||||||
throw new GeneralException("signature failed");
|
throw new GeneralException(context.getString(R.string.error_signatureFailed));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (signaturePassPhrase == null) {
|
if (signaturePassPhrase == null) {
|
||||||
throw new GeneralException("no pass phrase given");
|
throw new GeneralException(context.getString(R.string.error_noSignaturePassPhrase));
|
||||||
}
|
}
|
||||||
signaturePrivateKey =
|
signaturePrivateKey =
|
||||||
signingKey.extractPrivateKey(signaturePassPhrase.toCharArray(),
|
signingKey.extractPrivateKey(signaturePassPhrase.toCharArray(),
|
||||||
new BouncyCastleProvider());
|
new BouncyCastleProvider());
|
||||||
|
|
||||||
PGPSignatureGenerator signatureGenerator = null;
|
PGPSignatureGenerator signatureGenerator = null;
|
||||||
progress.setProgress("preparing data...", 0, 100);
|
progress.setProgress(R.string.progress_preparingStreams, 0, 100);
|
||||||
|
|
||||||
progress.setProgress("preparing signature...", 30, 100);
|
progress.setProgress(R.string.progress_preparingSignature, 30, 100);
|
||||||
signatureGenerator =
|
signatureGenerator =
|
||||||
new PGPSignatureGenerator(signingKey.getPublicKey().getAlgorithm(),
|
new PGPSignatureGenerator(signingKey.getPublicKey().getAlgorithm(),
|
||||||
hashAlgorithm,
|
hashAlgorithm,
|
||||||
@ -1367,7 +1370,7 @@ public class Apg {
|
|||||||
spGen.setSignerUserID(false, userId);
|
spGen.setSignerUserID(false, userId);
|
||||||
signatureGenerator.setHashedSubpackets(spGen.generate());
|
signatureGenerator.setHashedSubpackets(spGen.generate());
|
||||||
|
|
||||||
progress.setProgress("signing...", 40, 100);
|
progress.setProgress(R.string.progress_signing, 40, 100);
|
||||||
|
|
||||||
armorOut.beginClearText(hashAlgorithm);
|
armorOut.beginClearText(hashAlgorithm);
|
||||||
|
|
||||||
@ -1394,10 +1397,10 @@ public class Apg {
|
|||||||
signatureGenerator.generate().encode(bOut);
|
signatureGenerator.generate().encode(bOut);
|
||||||
armorOut.close();
|
armorOut.close();
|
||||||
|
|
||||||
progress.setProgress("done.", 100, 100);
|
progress.setProgress(R.string.progress_done, 100, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getDecryptionKeyId(InputStream inStream)
|
public static long getDecryptionKeyId(Context context, InputStream inStream)
|
||||||
throws GeneralException, NoAsymmetricEncryptionException, IOException {
|
throws GeneralException, NoAsymmetricEncryptionException, IOException {
|
||||||
InputStream in = PGPUtil.getDecoderStream(inStream);
|
InputStream in = PGPUtil.getDecoderStream(inStream);
|
||||||
PGPObjectFactory pgpF = new PGPObjectFactory(in);
|
PGPObjectFactory pgpF = new PGPObjectFactory(in);
|
||||||
@ -1412,7 +1415,7 @@ public class Apg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (enc == null) {
|
if (enc == null) {
|
||||||
throw new GeneralException("data not valid encryption data");
|
throw new GeneralException(context.getString(R.string.error_invalidData));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: currently we always only look at the first known key
|
// TODO: currently we always only look at the first known key
|
||||||
@ -1443,7 +1446,7 @@ public class Apg {
|
|||||||
return secretKey.getKeyID();
|
return secretKey.getKeyID();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasSymmetricEncryption(InputStream inStream)
|
public static boolean hasSymmetricEncryption(Context context, InputStream inStream)
|
||||||
throws GeneralException, IOException {
|
throws GeneralException, IOException {
|
||||||
InputStream in = PGPUtil.getDecoderStream(inStream);
|
InputStream in = PGPUtil.getDecoderStream(inStream);
|
||||||
PGPObjectFactory pgpF = new PGPObjectFactory(in);
|
PGPObjectFactory pgpF = new PGPObjectFactory(in);
|
||||||
@ -1458,7 +1461,7 @@ public class Apg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (enc == null) {
|
if (enc == null) {
|
||||||
throw new GeneralException("data not valid encryption data");
|
throw new GeneralException(context.getString(R.string.error_invalidData));
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator it = enc.getEncryptedDataObjects();
|
Iterator it = enc.getEncryptedDataObjects();
|
||||||
@ -1472,7 +1475,8 @@ public class Apg {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bundle decrypt(InputStream inStream, OutputStream outStream,
|
public static Bundle decrypt(Context context,
|
||||||
|
InputStream inStream, OutputStream outStream,
|
||||||
String passPhrase, ProgressDialogUpdater progress,
|
String passPhrase, ProgressDialogUpdater progress,
|
||||||
boolean assumeSymmetric)
|
boolean assumeSymmetric)
|
||||||
throws IOException, GeneralException, PGPException, SignatureException {
|
throws IOException, GeneralException, PGPException, SignatureException {
|
||||||
@ -1484,7 +1488,7 @@ public class Apg {
|
|||||||
long signatureKeyId = 0;
|
long signatureKeyId = 0;
|
||||||
|
|
||||||
int currentProgress = 0;
|
int currentProgress = 0;
|
||||||
progress.setProgress("reading data...", currentProgress, 100);
|
progress.setProgress(R.string.progress_readingData, currentProgress, 100);
|
||||||
|
|
||||||
if (o instanceof PGPEncryptedDataList) {
|
if (o instanceof PGPEncryptedDataList) {
|
||||||
enc = (PGPEncryptedDataList) o;
|
enc = (PGPEncryptedDataList) o;
|
||||||
@ -1493,7 +1497,7 @@ public class Apg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (enc == null) {
|
if (enc == null) {
|
||||||
throw new GeneralException("data not valid encryption data");
|
throw new GeneralException(context.getString(R.string.error_invalidData));
|
||||||
}
|
}
|
||||||
|
|
||||||
InputStream clear = null;
|
InputStream clear = null;
|
||||||
@ -1516,15 +1520,15 @@ public class Apg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pbe == null) {
|
if (pbe == null) {
|
||||||
throw new GeneralException("couldn't find a packet with symmetric encryption");
|
throw new GeneralException(context.getString(R.string.error_noSymmetricEncryptionPacket));
|
||||||
}
|
}
|
||||||
|
|
||||||
progress.setProgress("preparing stream...", currentProgress, 100);
|
progress.setProgress(R.string.progress_preparingStreams, currentProgress, 100);
|
||||||
clear = pbe.getDataStream(passPhrase.toCharArray(), new BouncyCastleProvider());
|
clear = pbe.getDataStream(passPhrase.toCharArray(), new BouncyCastleProvider());
|
||||||
encryptedData = pbe;
|
encryptedData = pbe;
|
||||||
currentProgress += 5;
|
currentProgress += 5;
|
||||||
} else {
|
} else {
|
||||||
progress.setProgress("finding key...", currentProgress, 100);
|
progress.setProgress(R.string.progress_findingKey, currentProgress, 100);
|
||||||
PGPPublicKeyEncryptedData pbe = null;
|
PGPPublicKeyEncryptedData pbe = null;
|
||||||
PGPSecretKey secretKey = null;
|
PGPSecretKey secretKey = null;
|
||||||
Iterator it = enc.getEncryptedDataObjects();
|
Iterator it = enc.getEncryptedDataObjects();
|
||||||
@ -1542,20 +1546,20 @@ public class Apg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (secretKey == null) {
|
if (secretKey == null) {
|
||||||
throw new GeneralException("couldn't find a secret key to decrypt");
|
throw new GeneralException(context.getString(R.string.error_noSecretKeyFound));
|
||||||
}
|
}
|
||||||
|
|
||||||
currentProgress += 5;
|
currentProgress += 5;
|
||||||
progress.setProgress("extracting key...", currentProgress, 100);
|
progress.setProgress(R.string.progress_extractingKey, currentProgress, 100);
|
||||||
PGPPrivateKey privateKey = null;
|
PGPPrivateKey privateKey = null;
|
||||||
try {
|
try {
|
||||||
privateKey = secretKey.extractPrivateKey(passPhrase.toCharArray(),
|
privateKey = secretKey.extractPrivateKey(passPhrase.toCharArray(),
|
||||||
new BouncyCastleProvider());
|
new BouncyCastleProvider());
|
||||||
} catch (PGPException e) {
|
} catch (PGPException e) {
|
||||||
throw new PGPException("wrong pass phrase");
|
throw new PGPException(context.getString(R.string.error_wrongPassPhrase));
|
||||||
}
|
}
|
||||||
currentProgress += 5;
|
currentProgress += 5;
|
||||||
progress.setProgress("preparing stream...", currentProgress, 100);
|
progress.setProgress(R.string.progress_preparingStreams, currentProgress, 100);
|
||||||
clear = pbe.getDataStream(privateKey, new BouncyCastleProvider());
|
clear = pbe.getDataStream(privateKey, new BouncyCastleProvider());
|
||||||
encryptedData = pbe;
|
encryptedData = pbe;
|
||||||
currentProgress += 5;
|
currentProgress += 5;
|
||||||
@ -1568,7 +1572,7 @@ public class Apg {
|
|||||||
int signatureIndex = -1;
|
int signatureIndex = -1;
|
||||||
|
|
||||||
if (dataChunk instanceof PGPCompressedData) {
|
if (dataChunk instanceof PGPCompressedData) {
|
||||||
progress.setProgress("decompressing data...", currentProgress, 100);
|
progress.setProgress(R.string.progress_decompressingData, currentProgress, 100);
|
||||||
PGPObjectFactory fact =
|
PGPObjectFactory fact =
|
||||||
new PGPObjectFactory(((PGPCompressedData) dataChunk).getDataStream());
|
new PGPObjectFactory(((PGPCompressedData) dataChunk).getDataStream());
|
||||||
dataChunk = fact.nextObject();
|
dataChunk = fact.nextObject();
|
||||||
@ -1577,7 +1581,7 @@ public class Apg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dataChunk instanceof PGPOnePassSignatureList) {
|
if (dataChunk instanceof PGPOnePassSignatureList) {
|
||||||
progress.setProgress("processing signature...", currentProgress, 100);
|
progress.setProgress(R.string.progress_processingSignature, currentProgress, 100);
|
||||||
returnData.putBoolean("signature", true);
|
returnData.putBoolean("signature", true);
|
||||||
PGPOnePassSignatureList sigList = (PGPOnePassSignatureList) dataChunk;
|
PGPOnePassSignatureList sigList = (PGPOnePassSignatureList) dataChunk;
|
||||||
for (int i = 0; i < sigList.size(); ++i) {
|
for (int i = 0; i < sigList.size(); ++i) {
|
||||||
@ -1614,7 +1618,7 @@ public class Apg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dataChunk instanceof PGPLiteralData) {
|
if (dataChunk instanceof PGPLiteralData) {
|
||||||
progress.setProgress("decrypting data...", currentProgress, 100);
|
progress.setProgress(R.string.progress_decrypting, currentProgress, 100);
|
||||||
PGPLiteralData literalData = (PGPLiteralData) dataChunk;
|
PGPLiteralData literalData = (PGPLiteralData) dataChunk;
|
||||||
OutputStream out = outStream;
|
OutputStream out = outStream;
|
||||||
|
|
||||||
@ -1647,7 +1651,7 @@ public class Apg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (signature != null) {
|
if (signature != null) {
|
||||||
progress.setProgress("verifying signature...", 90, 100);
|
progress.setProgress(R.string.progress_verifyingSignature, 90, 100);
|
||||||
PGPSignatureList signatureList = (PGPSignatureList) plainFact.nextObject();
|
PGPSignatureList signatureList = (PGPSignatureList) plainFact.nextObject();
|
||||||
PGPSignature messageSignature = (PGPSignature) signatureList.get(signatureIndex);
|
PGPSignature messageSignature = (PGPSignature) signatureList.get(signatureIndex);
|
||||||
if (signature.verify(messageSignature)) {
|
if (signature.verify(messageSignature)) {
|
||||||
@ -1660,7 +1664,7 @@ public class Apg {
|
|||||||
|
|
||||||
// TODO: add integrity somewhere
|
// TODO: add integrity somewhere
|
||||||
if (encryptedData.isIntegrityProtected()) {
|
if (encryptedData.isIntegrityProtected()) {
|
||||||
progress.setProgress("verifying integrity...", 95, 100);
|
progress.setProgress(R.string.progress_verifyingIntegrity, 95, 100);
|
||||||
if (encryptedData.verify()) {
|
if (encryptedData.verify()) {
|
||||||
// passed
|
// passed
|
||||||
} else {
|
} else {
|
||||||
@ -1670,11 +1674,12 @@ public class Apg {
|
|||||||
// no integrity check
|
// no integrity check
|
||||||
}
|
}
|
||||||
|
|
||||||
progress.setProgress("done.", 100, 100);
|
progress.setProgress(R.string.progress_done, 100, 100);
|
||||||
return returnData;
|
return returnData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bundle verifyText(InputStream inStream, OutputStream outStream,
|
public static Bundle verifyText(Context context,
|
||||||
|
InputStream inStream, OutputStream outStream,
|
||||||
ProgressDialogUpdater progress)
|
ProgressDialogUpdater progress)
|
||||||
throws IOException, GeneralException, PGPException, SignatureException {
|
throws IOException, GeneralException, PGPException, SignatureException {
|
||||||
Bundle returnData = new Bundle();
|
Bundle returnData = new Bundle();
|
||||||
@ -1682,7 +1687,7 @@ public class Apg {
|
|||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
ArmoredInputStream aIn = new ArmoredInputStream(inStream);
|
ArmoredInputStream aIn = new ArmoredInputStream(inStream);
|
||||||
|
|
||||||
progress.setProgress("reading data...", 0, 100);
|
progress.setProgress(R.string.progress_done, 0, 100);
|
||||||
|
|
||||||
// mostly taken from ClearSignedFileProcessor
|
// mostly taken from ClearSignedFileProcessor
|
||||||
ByteArrayOutputStream lineOut = new ByteArrayOutputStream();
|
ByteArrayOutputStream lineOut = new ByteArrayOutputStream();
|
||||||
@ -1707,12 +1712,12 @@ public class Apg {
|
|||||||
|
|
||||||
returnData.putBoolean("signature", true);
|
returnData.putBoolean("signature", true);
|
||||||
|
|
||||||
progress.setProgress("processing signature...", 60, 100);
|
progress.setProgress(R.string.progress_processingSignature, 60, 100);
|
||||||
PGPObjectFactory pgpFact = new PGPObjectFactory(aIn);
|
PGPObjectFactory pgpFact = new PGPObjectFactory(aIn);
|
||||||
|
|
||||||
PGPSignatureList sigList = (PGPSignatureList) pgpFact.nextObject();
|
PGPSignatureList sigList = (PGPSignatureList) pgpFact.nextObject();
|
||||||
if (sigList == null) {
|
if (sigList == null) {
|
||||||
throw new GeneralException("corrupt data");
|
throw new GeneralException(context.getString(R.string.error_corruptData));
|
||||||
}
|
}
|
||||||
PGPSignature signature = null;
|
PGPSignature signature = null;
|
||||||
long signatureKeyId = 0;
|
long signatureKeyId = 0;
|
||||||
@ -1741,7 +1746,7 @@ public class Apg {
|
|||||||
|
|
||||||
if (signature == null) {
|
if (signature == null) {
|
||||||
returnData.putBoolean("signatureUnknown", true);
|
returnData.putBoolean("signatureUnknown", true);
|
||||||
progress.setProgress("done.", 100, 100);
|
progress.setProgress(R.string.progress_done, 100, 100);
|
||||||
return returnData;
|
return returnData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1767,7 +1772,7 @@ public class Apg {
|
|||||||
|
|
||||||
returnData.putBoolean("signatureSuccess", signature.verify());
|
returnData.putBoolean("signatureSuccess", signature.verify());
|
||||||
|
|
||||||
progress.setProgress("done.", 100, 100);
|
progress.setProgress(R.string.progress_done, 100, 100);
|
||||||
return returnData;
|
return returnData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1782,18 +1787,15 @@ public class Apg {
|
|||||||
|
|
||||||
// taken from ClearSignedFileProcessor in BC
|
// taken from ClearSignedFileProcessor in BC
|
||||||
private static int readInputLine(ByteArrayOutputStream bOut, InputStream fIn)
|
private static int readInputLine(ByteArrayOutputStream bOut, InputStream fIn)
|
||||||
throws IOException
|
throws IOException {
|
||||||
{
|
|
||||||
bOut.reset();
|
bOut.reset();
|
||||||
|
|
||||||
int lookAhead = -1;
|
int lookAhead = -1;
|
||||||
int ch;
|
int ch;
|
||||||
|
|
||||||
while ((ch = fIn.read()) >= 0)
|
while ((ch = fIn.read()) >= 0) {
|
||||||
{
|
|
||||||
bOut.write(ch);
|
bOut.write(ch);
|
||||||
if (ch == '\r' || ch == '\n')
|
if (ch == '\r' || ch == '\n') {
|
||||||
{
|
|
||||||
lookAhead = readPassedEOL(bOut, ch, fIn);
|
lookAhead = readPassedEOL(bOut, ch, fIn);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1839,8 +1841,7 @@ public class Apg {
|
|||||||
private static void processLine(PGPSignature sig, byte[] line)
|
private static void processLine(PGPSignature sig, byte[] line)
|
||||||
throws SignatureException, IOException {
|
throws SignatureException, IOException {
|
||||||
int length = getLengthWithoutWhiteSpace(line);
|
int length = getLengthWithoutWhiteSpace(line);
|
||||||
if (length > 0)
|
if (length > 0) {
|
||||||
{
|
|
||||||
sig.update(line, 0, length);
|
sig.update(line, 0, length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1848,8 +1849,7 @@ public class Apg {
|
|||||||
private static void processLine(OutputStream aOut, PGPSignatureGenerator sGen, byte[] line)
|
private static void processLine(OutputStream aOut, PGPSignatureGenerator sGen, byte[] line)
|
||||||
throws SignatureException, IOException {
|
throws SignatureException, IOException {
|
||||||
int length = getLengthWithoutWhiteSpace(line);
|
int length = getLengthWithoutWhiteSpace(line);
|
||||||
if (length > 0)
|
if (length > 0) {
|
||||||
{
|
|
||||||
sGen.update(line, 0, length);
|
sGen.update(line, 0, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1857,7 +1857,7 @@ public class Apg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static int getLengthWithoutSeparator(byte[] line) {
|
private static int getLengthWithoutSeparator(byte[] line) {
|
||||||
int end = line.length - 1;
|
int end = line.length - 1;
|
||||||
|
|
||||||
while (end >= 0 && isLineEnding(line[end])) {
|
while (end >= 0 && isLineEnding(line[end])) {
|
||||||
end--;
|
end--;
|
||||||
@ -1871,7 +1871,7 @@ public class Apg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static int getLengthWithoutWhiteSpace(byte[] line) {
|
private static int getLengthWithoutWhiteSpace(byte[] line) {
|
||||||
int end = line.length - 1;
|
int end = line.length - 1;
|
||||||
|
|
||||||
while (end >= 0 && isWhiteSpace(line[end])) {
|
while (end >= 0 && isWhiteSpace(line[end])) {
|
||||||
end--;
|
end--;
|
||||||
|
@ -212,7 +212,10 @@ public class BaseActivity extends Activity
|
|||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void setProgress(int resourceId, int progress, int max) {
|
||||||
|
setProgress(getString(resourceId), progress, max);
|
||||||
|
}
|
||||||
|
|
||||||
public void setProgress(int progress, int max) {
|
public void setProgress(int progress, int max) {
|
||||||
Message msg = new Message();
|
Message msg = new Message();
|
||||||
Bundle data = new Bundle();
|
Bundle data = new Bundle();
|
||||||
@ -223,7 +226,6 @@ public class BaseActivity extends Activity
|
|||||||
mHandler.sendMessage(msg);
|
mHandler.sendMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setProgress(String message, int progress, int max) {
|
public void setProgress(String message, int progress, int max) {
|
||||||
Message msg = new Message();
|
Message msg = new Message();
|
||||||
Bundle data = new Bundle();
|
Bundle data = new Bundle();
|
||||||
|
@ -350,7 +350,7 @@ public class DecryptActivity extends BaseActivity {
|
|||||||
in = new ByteArrayInputStream(mMessage.getText().toString().getBytes());
|
in = new ByteArrayInputStream(mMessage.getText().toString().getBytes());
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
setSecretKeyId(Apg.getDecryptionKeyId(in));
|
setSecretKeyId(Apg.getDecryptionKeyId(this, in));
|
||||||
if (getSecretKeyId() == 0) {
|
if (getSecretKeyId() == 0) {
|
||||||
throw new Apg.GeneralException(getString(R.string.error_noSecretKeyFound));
|
throw new Apg.GeneralException(getString(R.string.error_noSecretKeyFound));
|
||||||
}
|
}
|
||||||
@ -364,7 +364,7 @@ public class DecryptActivity extends BaseActivity {
|
|||||||
} else {
|
} else {
|
||||||
in = new ByteArrayInputStream(mMessage.getText().toString().getBytes());
|
in = new ByteArrayInputStream(mMessage.getText().toString().getBytes());
|
||||||
}
|
}
|
||||||
if (!Apg.hasSymmetricEncryption(in)) {
|
if (!Apg.hasSymmetricEncryption(this, in)) {
|
||||||
throw new Apg.GeneralException(getString(R.string.error_noKnownEncryptionFound));
|
throw new Apg.GeneralException(getString(R.string.error_noKnownEncryptionFound));
|
||||||
}
|
}
|
||||||
mAssumeSymmetricEncryption = true;
|
mAssumeSymmetricEncryption = true;
|
||||||
@ -439,9 +439,10 @@ public class DecryptActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mSignedOnly) {
|
if (mSignedOnly) {
|
||||||
data = Apg.verifyText(in, out, this);
|
data = Apg.verifyText(this, in, out, this);
|
||||||
} else {
|
} else {
|
||||||
data = Apg.decrypt(in, out, Apg.getPassPhrase(), this, mAssumeSymmetricEncryption);
|
data = Apg.decrypt(this, in, out, Apg.getPassPhrase(),
|
||||||
|
this, mAssumeSymmetricEncryption);
|
||||||
}
|
}
|
||||||
|
|
||||||
out.close();
|
out.close();
|
||||||
|
@ -543,10 +543,10 @@ public class EncryptActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (signOnly) {
|
if (signOnly) {
|
||||||
Apg.signText(in, out, getSecretKeyId(),
|
Apg.signText(this, in, out, getSecretKeyId(),
|
||||||
Apg.getPassPhrase(), getDefaultHashAlgorithm(), this);
|
Apg.getPassPhrase(), getDefaultHashAlgorithm(), this);
|
||||||
} else {
|
} else {
|
||||||
Apg.encrypt(in, out, size, useAsciiArmour,
|
Apg.encrypt(this, in, out, size, useAsciiArmour,
|
||||||
encryptionKeyIds, signatureKeyId,
|
encryptionKeyIds, signatureKeyId,
|
||||||
Apg.getPassPhrase(), this,
|
Apg.getPassPhrase(), this,
|
||||||
getDefaultEncryptionAlgorithm(), getDefaultHashAlgorithm(),
|
getDefaultEncryptionAlgorithm(), getDefaultHashAlgorithm(),
|
||||||
|
@ -18,5 +18,6 @@ package org.thialfihar.android.apg;
|
|||||||
|
|
||||||
public interface ProgressDialogUpdater {
|
public interface ProgressDialogUpdater {
|
||||||
void setProgress(String message, int current, int total);
|
void setProgress(String message, int current, int total);
|
||||||
|
void setProgress(int resourceId, int current, int total);
|
||||||
void setProgress(int current, int total);
|
void setProgress(int current, int total);
|
||||||
}
|
}
|
||||||
|
@ -301,7 +301,8 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
|||||||
if (mEditors.getChildCount() > 0) {
|
if (mEditors.getChildCount() > 0) {
|
||||||
masterKey = ((KeyEditor) mEditors.getChildAt(0)).getValue();
|
masterKey = ((KeyEditor) mEditors.getChildAt(0)).getValue();
|
||||||
}
|
}
|
||||||
mNewKey = Apg.createKey(mNewKeyAlgorithmChoice.getId(),
|
mNewKey = Apg.createKey(getContext(),
|
||||||
|
mNewKeyAlgorithmChoice.getId(),
|
||||||
mNewKeySize, Apg.getPassPhrase(), masterKey);
|
mNewKeySize, Apg.getPassPhrase(), masterKey);
|
||||||
} catch (NoSuchProviderException e) {
|
} catch (NoSuchProviderException e) {
|
||||||
error = e.getMessage();
|
error = e.getMessage();
|
||||||
|
Loading…
Reference in New Issue
Block a user