aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java
diff options
context:
space:
mode:
authorJoey Castillo <jose.castillo@gmail.com>2015-05-06 13:08:03 -0400
committerJoey Castillo <jose.castillo@gmail.com>2015-05-12 14:44:26 -0400
commit76241e90ad440bedaf40f148ba0584e06064096a (patch)
treefeee753bb557be2f4a589126097c8942525b8b2e /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java
parent5c44f8400970de5943fd6c5e804dfa394f3deb01 (diff)
downloadopen-keychain-76241e90ad440bedaf40f148ba0584e06064096a.tar.gz
open-keychain-76241e90ad440bedaf40f148ba0584e06064096a.tar.bz2
open-keychain-76241e90ad440bedaf40f148ba0584e06064096a.zip
Adding NFC Key to Card operation, accessible from Edit Key activity.
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java24
1 files changed, 24 insertions, 0 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java
index 39d0a2f1d..fd023576b 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java
@@ -33,6 +33,7 @@ import org.spongycastle.openpgp.operator.PBESecretKeyDecryptor;
import org.spongycastle.openpgp.operator.PGPContentSignerBuilder;
import org.spongycastle.openpgp.operator.PublicKeyDataDecryptorFactory;
import org.spongycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder;
+import org.spongycastle.openpgp.operator.jcajce.JcaPGPKeyConverter;
import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder;
import org.spongycastle.openpgp.operator.jcajce.JcePublicKeyDataDecryptorFactoryBuilder;
import org.spongycastle.openpgp.operator.jcajce.NfcSyncPGPContentSignerBuilder;
@@ -45,6 +46,8 @@ import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Passphrase;
import java.nio.ByteBuffer;
+import java.security.PrivateKey;
+import java.security.interfaces.RSAPrivateCrtKey;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
@@ -281,6 +284,27 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey {
}
}
+ // For use only in card export; returns the secret key in Chinese Remainder Theorem format.
+ public RSAPrivateCrtKey getCrtSecretKey() throws PgpGeneralException {
+ if (mPrivateKeyState == PRIVATE_KEY_STATE_LOCKED) {
+ throw new PgpGeneralException("Cannot get secret key attributes while key is locked.");
+ }
+
+ if (mPrivateKeyState == PRIVATE_KEY_STATE_DIVERT_TO_CARD) {
+ throw new PgpGeneralException("Cannot get secret key attributes of divert-to-card key.");
+ }
+
+ JcaPGPKeyConverter keyConverter = new JcaPGPKeyConverter();
+ PrivateKey retVal;
+ try {
+ retVal = keyConverter.getPrivateKey(mPrivateKey);
+ } catch (PGPException e) {
+ throw new PgpGeneralException("Error converting private key!", e);
+ }
+
+ return (RSAPrivateCrtKey)retVal;
+ }
+
public byte[] getIv() {
return mSecretKey.getIV();
}