From cce0605ac3b0991164e21b1130b609361727976f Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Thu, 1 Jul 2021 18:55:21 +0200 Subject: [PATCH] Remove probably buggy, unused code --- .../BcImplementationFactory.java | 5 ---- .../implementation/ImplementationFactory.java | 7 ------ .../JceImplementationFactory.java | 23 ------------------- 3 files changed, 35 deletions(-) diff --git a/pgpainless-core/src/main/java/org/pgpainless/implementation/BcImplementationFactory.java b/pgpainless-core/src/main/java/org/pgpainless/implementation/BcImplementationFactory.java index 418c9628..bd358061 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/implementation/BcImplementationFactory.java +++ b/pgpainless-core/src/main/java/org/pgpainless/implementation/BcImplementationFactory.java @@ -139,11 +139,6 @@ public class BcImplementationFactory extends ImplementationFactory { return new BcPGPKeyPair(algorithm.getAlgorithmId(), jceToBcKeyPair(algorithm, keyPair, creationDate), creationDate); } - @Override - public PGPKeyPair getPGPKeyPair(PublicKeyAlgorithm algorithm, AsymmetricCipherKeyPair keyPair, Date creationDate) throws PGPException { - return new BcPGPKeyPair(algorithm.getAlgorithmId(), keyPair, creationDate); - } - @Override public PBESecretKeyEncryptor getPBESecretKeyEncryptor(SymmetricKeyAlgorithm encryptionAlgorithm, HashAlgorithm hashAlgorithm, int s2kCount, Passphrase passphrase) throws PGPException { return new BcPBESecretKeyEncryptorBuilder( diff --git a/pgpainless-core/src/main/java/org/pgpainless/implementation/ImplementationFactory.java b/pgpainless-core/src/main/java/org/pgpainless/implementation/ImplementationFactory.java index 4e5bd7d5..d7ee5370 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/implementation/ImplementationFactory.java +++ b/pgpainless-core/src/main/java/org/pgpainless/implementation/ImplementationFactory.java @@ -15,13 +15,9 @@ */ package org.pgpainless.implementation; -import java.io.IOException; import java.security.KeyPair; -import java.security.NoSuchAlgorithmException; -import java.security.spec.InvalidKeySpecException; import java.util.Date; -import org.bouncycastle.crypto.AsymmetricCipherKeyPair; import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPKeyPair; import org.bouncycastle.openpgp.PGPPrivateKey; @@ -112,9 +108,6 @@ public abstract class ImplementationFactory { public abstract PGPKeyPair getPGPKeyPair(PublicKeyAlgorithm algorithm, KeyPair keyPair, Date creationDate) throws PGPException; - public abstract PGPKeyPair getPGPKeyPair(PublicKeyAlgorithm algorithm, AsymmetricCipherKeyPair keyPair, Date creationDate) - throws PGPException, NoSuchAlgorithmException, IOException, InvalidKeySpecException; - public abstract PBESecretKeyEncryptor getPBESecretKeyEncryptor(SymmetricKeyAlgorithm encryptionAlgorithm, HashAlgorithm hashAlgorithm, int s2kCount, Passphrase passphrase) throws PGPException; diff --git a/pgpainless-core/src/main/java/org/pgpainless/implementation/JceImplementationFactory.java b/pgpainless-core/src/main/java/org/pgpainless/implementation/JceImplementationFactory.java index f1f8be0a..c7e311b3 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/implementation/JceImplementationFactory.java +++ b/pgpainless-core/src/main/java/org/pgpainless/implementation/JceImplementationFactory.java @@ -15,18 +15,9 @@ */ package org.pgpainless.implementation; -import java.io.IOException; -import java.security.KeyFactory; import java.security.KeyPair; -import java.security.NoSuchAlgorithmException; -import java.security.spec.InvalidKeySpecException; -import java.security.spec.PKCS8EncodedKeySpec; -import java.security.spec.X509EncodedKeySpec; import java.util.Date; -import org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import org.bouncycastle.crypto.util.PrivateKeyInfoFactory; -import org.bouncycastle.crypto.util.SubjectPublicKeyInfoFactory; import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPKeyPair; import org.bouncycastle.openpgp.PGPPrivateKey; @@ -136,10 +127,6 @@ public class JceImplementationFactory extends ImplementationFactory { return new JcaPGPKeyPair(algorithm.getAlgorithmId(), keyPair, creationDate); } - public PGPKeyPair getPGPKeyPair(PublicKeyAlgorithm algorithm, AsymmetricCipherKeyPair keyPair, Date creationDate) throws PGPException, NoSuchAlgorithmException, IOException, InvalidKeySpecException { - return new JcaPGPKeyPair(algorithm.getAlgorithmId(), bcToJceKeyPair(keyPair), creationDate); - } - public PBESecretKeyEncryptor getPBESecretKeyEncryptor(SymmetricKeyAlgorithm encryptionAlgorithm, HashAlgorithm hashAlgorithm, int s2kCount, Passphrase passphrase) throws PGPException { return new JcePBESecretKeyEncryptorBuilder( encryptionAlgorithm.getAlgorithmId(), @@ -148,14 +135,4 @@ public class JceImplementationFactory extends ImplementationFactory { .setProvider(ProviderFactory.getProvider()) .build(passphrase.getChars()); } - - private KeyPair bcToJceKeyPair(AsymmetricCipherKeyPair keyPair) - throws NoSuchAlgorithmException, InvalidKeySpecException, IOException { - byte[] pkcs8Encoded = PrivateKeyInfoFactory.createPrivateKeyInfo(keyPair.getPrivate()).getEncoded(); - PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(pkcs8Encoded); - byte[] spkiEncoded = SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(keyPair.getPublic()).getEncoded(); - X509EncodedKeySpec spkiKeySpec = new X509EncodedKeySpec(spkiEncoded); - KeyFactory keyFac = KeyFactory.getInstance("RSA"); - return new KeyPair(keyFac.generatePublic(spkiKeySpec), keyFac.generatePrivate(pkcs8KeySpec)); - } }