mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-12-12 15:21:08 +01:00
Kotlin conversion: ImplementationFactory classes
This commit is contained in:
parent
d707dcf74a
commit
1cdce5c93a
11 changed files with 299 additions and 430 deletions
|
|
@ -1,154 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2020 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.implementation;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.security.KeyPair;
|
||||
import java.util.Date;
|
||||
|
||||
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
|
||||
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPKeyPair;
|
||||
import org.bouncycastle.openpgp.PGPObjectFactory;
|
||||
import org.bouncycastle.openpgp.PGPPrivateKey;
|
||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||
import org.bouncycastle.openpgp.PGPSessionKey;
|
||||
import org.bouncycastle.openpgp.bc.BcPGPObjectFactory;
|
||||
import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
|
||||
import org.bouncycastle.openpgp.operator.PBEDataDecryptorFactory;
|
||||
import org.bouncycastle.openpgp.operator.PBEKeyEncryptionMethodGenerator;
|
||||
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor;
|
||||
import org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor;
|
||||
import org.bouncycastle.openpgp.operator.PGPContentSignerBuilder;
|
||||
import org.bouncycastle.openpgp.operator.PGPContentVerifierBuilderProvider;
|
||||
import org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder;
|
||||
import org.bouncycastle.openpgp.operator.PGPDigestCalculator;
|
||||
import org.bouncycastle.openpgp.operator.PublicKeyDataDecryptorFactory;
|
||||
import org.bouncycastle.openpgp.operator.PublicKeyKeyEncryptionMethodGenerator;
|
||||
import org.bouncycastle.openpgp.operator.SessionKeyDataDecryptorFactory;
|
||||
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator;
|
||||
import org.bouncycastle.openpgp.operator.bc.BcPBEDataDecryptorFactory;
|
||||
import org.bouncycastle.openpgp.operator.bc.BcPBEKeyEncryptionMethodGenerator;
|
||||
import org.bouncycastle.openpgp.operator.bc.BcPBESecretKeyDecryptorBuilder;
|
||||
import org.bouncycastle.openpgp.operator.bc.BcPBESecretKeyEncryptorBuilder;
|
||||
import org.bouncycastle.openpgp.operator.bc.BcPGPContentSignerBuilder;
|
||||
import org.bouncycastle.openpgp.operator.bc.BcPGPContentVerifierBuilderProvider;
|
||||
import org.bouncycastle.openpgp.operator.bc.BcPGPDataEncryptorBuilder;
|
||||
import org.bouncycastle.openpgp.operator.bc.BcPGPDigestCalculatorProvider;
|
||||
import org.bouncycastle.openpgp.operator.bc.BcPGPKeyConverter;
|
||||
import org.bouncycastle.openpgp.operator.bc.BcPGPKeyPair;
|
||||
import org.bouncycastle.openpgp.operator.bc.BcPublicKeyDataDecryptorFactory;
|
||||
import org.bouncycastle.openpgp.operator.bc.BcPublicKeyKeyEncryptionMethodGenerator;
|
||||
import org.bouncycastle.openpgp.operator.bc.BcSessionKeyDataDecryptorFactory;
|
||||
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair;
|
||||
import org.pgpainless.algorithm.HashAlgorithm;
|
||||
import org.pgpainless.algorithm.PublicKeyAlgorithm;
|
||||
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
||||
import org.pgpainless.util.Passphrase;
|
||||
|
||||
public class BcImplementationFactory extends ImplementationFactory {
|
||||
|
||||
@Override
|
||||
public PBESecretKeyEncryptor getPBESecretKeyEncryptor(SymmetricKeyAlgorithm symmetricKeyAlgorithm,
|
||||
PGPDigestCalculator digestCalculator,
|
||||
Passphrase passphrase) {
|
||||
return new BcPBESecretKeyEncryptorBuilder(symmetricKeyAlgorithm.getAlgorithmId(), digestCalculator)
|
||||
.build(passphrase.getChars());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PBESecretKeyDecryptor getPBESecretKeyDecryptor(Passphrase passphrase) {
|
||||
return new BcPBESecretKeyDecryptorBuilder(getPGPDigestCalculatorProvider())
|
||||
.build(passphrase.getChars());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BcPGPDigestCalculatorProvider getPGPDigestCalculatorProvider() {
|
||||
return new BcPGPDigestCalculatorProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PGPContentVerifierBuilderProvider getPGPContentVerifierBuilderProvider() {
|
||||
return new BcPGPContentVerifierBuilderProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PGPContentSignerBuilder getPGPContentSignerBuilder(int keyAlgorithm, int hashAlgorithm) {
|
||||
return new BcPGPContentSignerBuilder(keyAlgorithm, hashAlgorithm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeyFingerPrintCalculator getKeyFingerprintCalculator() {
|
||||
return new BcKeyFingerprintCalculator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PBEDataDecryptorFactory getPBEDataDecryptorFactory(Passphrase passphrase) {
|
||||
return new BcPBEDataDecryptorFactory(passphrase.getChars(), getPGPDigestCalculatorProvider());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PublicKeyDataDecryptorFactory getPublicKeyDataDecryptorFactory(PGPPrivateKey privateKey) {
|
||||
return new BcPublicKeyDataDecryptorFactory(privateKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SessionKeyDataDecryptorFactory getSessionKeyDataDecryptorFactory(PGPSessionKey sessionKey) {
|
||||
return new BcSessionKeyDataDecryptorFactory(sessionKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PublicKeyKeyEncryptionMethodGenerator getPublicKeyKeyEncryptionMethodGenerator(PGPPublicKey key) {
|
||||
return new BcPublicKeyKeyEncryptionMethodGenerator(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PBEKeyEncryptionMethodGenerator getPBEKeyEncryptionMethodGenerator(Passphrase passphrase) {
|
||||
return new BcPBEKeyEncryptionMethodGenerator(passphrase.getChars());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PGPDataEncryptorBuilder getPGPDataEncryptorBuilder(int symmetricKeyAlgorithm) {
|
||||
return new BcPGPDataEncryptorBuilder(symmetricKeyAlgorithm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PGPKeyPair getPGPKeyPair(PublicKeyAlgorithm algorithm, KeyPair keyPair, Date creationDate)
|
||||
throws PGPException {
|
||||
return new BcPGPKeyPair(algorithm.getAlgorithmId(), jceToBcKeyPair(algorithm, keyPair, creationDate), creationDate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PBESecretKeyEncryptor getPBESecretKeyEncryptor(SymmetricKeyAlgorithm encryptionAlgorithm, HashAlgorithm hashAlgorithm, int s2kCount, Passphrase passphrase) throws PGPException {
|
||||
return new BcPBESecretKeyEncryptorBuilder(
|
||||
encryptionAlgorithm.getAlgorithmId(),
|
||||
getPGPDigestCalculator(hashAlgorithm),
|
||||
s2kCount)
|
||||
.build(passphrase.getChars());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PGPObjectFactory getPGPObjectFactory(byte[] bytes) {
|
||||
return new BcPGPObjectFactory(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PGPObjectFactory getPGPObjectFactory(InputStream inputStream) {
|
||||
return new BcPGPObjectFactory(inputStream);
|
||||
}
|
||||
|
||||
private AsymmetricCipherKeyPair jceToBcKeyPair(PublicKeyAlgorithm algorithm,
|
||||
KeyPair keyPair,
|
||||
Date creationDate) throws PGPException {
|
||||
BcPGPKeyConverter converter = new BcPGPKeyConverter();
|
||||
|
||||
PGPKeyPair pair = new JcaPGPKeyPair(algorithm.getAlgorithmId(), keyPair, creationDate);
|
||||
AsymmetricKeyParameter publicKey = converter.getPublicKey(pair.getPublicKey());
|
||||
AsymmetricKeyParameter privateKey = converter.getPrivateKey(pair.getPrivateKey());
|
||||
|
||||
return new AsymmetricCipherKeyPair(publicKey, privateKey);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,119 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2020 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.implementation;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.security.KeyPair;
|
||||
import java.util.Date;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPKeyPair;
|
||||
import org.bouncycastle.openpgp.PGPObjectFactory;
|
||||
import org.bouncycastle.openpgp.PGPPrivateKey;
|
||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||
import org.bouncycastle.openpgp.PGPSessionKey;
|
||||
import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
|
||||
import org.bouncycastle.openpgp.operator.PBEDataDecryptorFactory;
|
||||
import org.bouncycastle.openpgp.operator.PBEKeyEncryptionMethodGenerator;
|
||||
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor;
|
||||
import org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor;
|
||||
import org.bouncycastle.openpgp.operator.PGPContentSignerBuilder;
|
||||
import org.bouncycastle.openpgp.operator.PGPContentVerifierBuilderProvider;
|
||||
import org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder;
|
||||
import org.bouncycastle.openpgp.operator.PGPDigestCalculator;
|
||||
import org.bouncycastle.openpgp.operator.PGPDigestCalculatorProvider;
|
||||
import org.bouncycastle.openpgp.operator.PublicKeyDataDecryptorFactory;
|
||||
import org.bouncycastle.openpgp.operator.PublicKeyKeyEncryptionMethodGenerator;
|
||||
import org.bouncycastle.openpgp.operator.SessionKeyDataDecryptorFactory;
|
||||
import org.pgpainless.algorithm.HashAlgorithm;
|
||||
import org.pgpainless.algorithm.PublicKeyAlgorithm;
|
||||
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
||||
import org.pgpainless.util.Passphrase;
|
||||
import org.pgpainless.util.SessionKey;
|
||||
|
||||
public abstract class ImplementationFactory {
|
||||
|
||||
private static ImplementationFactory FACTORY_IMPLEMENTATION;
|
||||
|
||||
public static void setFactoryImplementation(ImplementationFactory implementation) {
|
||||
FACTORY_IMPLEMENTATION = implementation;
|
||||
}
|
||||
|
||||
public static ImplementationFactory getInstance() {
|
||||
if (FACTORY_IMPLEMENTATION == null) {
|
||||
FACTORY_IMPLEMENTATION = new BcImplementationFactory();
|
||||
}
|
||||
return FACTORY_IMPLEMENTATION;
|
||||
}
|
||||
|
||||
public abstract PBESecretKeyEncryptor getPBESecretKeyEncryptor(SymmetricKeyAlgorithm symmetricKeyAlgorithm,
|
||||
PGPDigestCalculator digestCalculator,
|
||||
Passphrase passphrase);
|
||||
|
||||
public abstract PBESecretKeyDecryptor getPBESecretKeyDecryptor(Passphrase passphrase) throws PGPException;
|
||||
|
||||
public PGPDigestCalculator getV4FingerprintCalculator() throws PGPException {
|
||||
return getPGPDigestCalculator(HashAlgorithm.SHA1);
|
||||
}
|
||||
|
||||
public PGPDigestCalculator getPGPDigestCalculator(HashAlgorithm algorithm) throws PGPException {
|
||||
return getPGPDigestCalculator(algorithm.getAlgorithmId());
|
||||
}
|
||||
|
||||
public PGPDigestCalculator getPGPDigestCalculator(int algorithm) throws PGPException {
|
||||
return getPGPDigestCalculatorProvider().get(algorithm);
|
||||
}
|
||||
|
||||
public abstract PGPDigestCalculatorProvider getPGPDigestCalculatorProvider() throws PGPException;
|
||||
|
||||
public abstract PGPContentVerifierBuilderProvider getPGPContentVerifierBuilderProvider();
|
||||
|
||||
public PGPContentSignerBuilder getPGPContentSignerBuilder(PublicKeyAlgorithm keyAlgorithm, HashAlgorithm hashAlgorithm) {
|
||||
return getPGPContentSignerBuilder(keyAlgorithm.getAlgorithmId(), hashAlgorithm.getAlgorithmId());
|
||||
}
|
||||
|
||||
public abstract PGPContentSignerBuilder getPGPContentSignerBuilder(int keyAlgorithm, int hashAlgorithm);
|
||||
|
||||
public abstract KeyFingerPrintCalculator getKeyFingerprintCalculator();
|
||||
|
||||
public abstract PBEDataDecryptorFactory getPBEDataDecryptorFactory(Passphrase passphrase) throws PGPException;
|
||||
|
||||
public abstract PublicKeyDataDecryptorFactory getPublicKeyDataDecryptorFactory(PGPPrivateKey privateKey);
|
||||
|
||||
public SessionKeyDataDecryptorFactory getSessionKeyDataDecryptorFactory(SessionKey sessionKey) {
|
||||
PGPSessionKey pgpSessionKey = new PGPSessionKey(
|
||||
sessionKey.getAlgorithm().getAlgorithmId(),
|
||||
sessionKey.getKey()
|
||||
);
|
||||
return getSessionKeyDataDecryptorFactory(pgpSessionKey);
|
||||
}
|
||||
|
||||
public abstract SessionKeyDataDecryptorFactory getSessionKeyDataDecryptorFactory(PGPSessionKey sessionKey);
|
||||
|
||||
public abstract PublicKeyKeyEncryptionMethodGenerator getPublicKeyKeyEncryptionMethodGenerator(PGPPublicKey key);
|
||||
|
||||
public abstract PBEKeyEncryptionMethodGenerator getPBEKeyEncryptionMethodGenerator(Passphrase passphrase);
|
||||
|
||||
public PGPDataEncryptorBuilder getPGPDataEncryptorBuilder(SymmetricKeyAlgorithm symmetricKeyAlgorithm) {
|
||||
return getPGPDataEncryptorBuilder(symmetricKeyAlgorithm.getAlgorithmId());
|
||||
}
|
||||
|
||||
public abstract PGPDataEncryptorBuilder getPGPDataEncryptorBuilder(int symmetricKeyAlgorithm);
|
||||
|
||||
public abstract PGPKeyPair getPGPKeyPair(PublicKeyAlgorithm algorithm, KeyPair keyPair, Date creationDate) throws PGPException;
|
||||
|
||||
public abstract PBESecretKeyEncryptor getPBESecretKeyEncryptor(SymmetricKeyAlgorithm encryptionAlgorithm,
|
||||
HashAlgorithm hashAlgorithm, int s2kCount,
|
||||
Passphrase passphrase) throws PGPException;
|
||||
|
||||
public abstract PGPObjectFactory getPGPObjectFactory(InputStream inputStream);
|
||||
|
||||
public abstract PGPObjectFactory getPGPObjectFactory(byte[] bytes);
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,141 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2020 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.implementation;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.security.KeyPair;
|
||||
import java.util.Date;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPKeyPair;
|
||||
import org.bouncycastle.openpgp.PGPObjectFactory;
|
||||
import org.bouncycastle.openpgp.PGPPrivateKey;
|
||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||
import org.bouncycastle.openpgp.PGPSessionKey;
|
||||
import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
|
||||
import org.bouncycastle.openpgp.operator.PBEDataDecryptorFactory;
|
||||
import org.bouncycastle.openpgp.operator.PBEKeyEncryptionMethodGenerator;
|
||||
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor;
|
||||
import org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor;
|
||||
import org.bouncycastle.openpgp.operator.PGPContentSignerBuilder;
|
||||
import org.bouncycastle.openpgp.operator.PGPContentVerifierBuilderProvider;
|
||||
import org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder;
|
||||
import org.bouncycastle.openpgp.operator.PGPDigestCalculator;
|
||||
import org.bouncycastle.openpgp.operator.PGPDigestCalculatorProvider;
|
||||
import org.bouncycastle.openpgp.operator.PublicKeyDataDecryptorFactory;
|
||||
import org.bouncycastle.openpgp.operator.PublicKeyKeyEncryptionMethodGenerator;
|
||||
import org.bouncycastle.openpgp.operator.SessionKeyDataDecryptorFactory;
|
||||
import org.bouncycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator;
|
||||
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder;
|
||||
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentVerifierBuilderProvider;
|
||||
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder;
|
||||
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair;
|
||||
import org.bouncycastle.openpgp.operator.jcajce.JcePBEDataDecryptorFactoryBuilder;
|
||||
import org.bouncycastle.openpgp.operator.jcajce.JcePBEKeyEncryptionMethodGenerator;
|
||||
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder;
|
||||
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder;
|
||||
import org.bouncycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder;
|
||||
import org.bouncycastle.openpgp.operator.jcajce.JcePublicKeyDataDecryptorFactoryBuilder;
|
||||
import org.bouncycastle.openpgp.operator.jcajce.JcePublicKeyKeyEncryptionMethodGenerator;
|
||||
import org.bouncycastle.openpgp.operator.jcajce.JceSessionKeyDataDecryptorFactoryBuilder;
|
||||
import org.pgpainless.algorithm.HashAlgorithm;
|
||||
import org.pgpainless.algorithm.PublicKeyAlgorithm;
|
||||
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
||||
import org.pgpainless.provider.ProviderFactory;
|
||||
import org.pgpainless.util.Passphrase;
|
||||
|
||||
public class JceImplementationFactory extends ImplementationFactory {
|
||||
|
||||
public PBESecretKeyEncryptor getPBESecretKeyEncryptor(SymmetricKeyAlgorithm symmetricKeyAlgorithm, PGPDigestCalculator digestCalculator, Passphrase passphrase) {
|
||||
return new JcePBESecretKeyEncryptorBuilder(symmetricKeyAlgorithm.getAlgorithmId(), digestCalculator)
|
||||
.setProvider(ProviderFactory.getProvider())
|
||||
.build(passphrase.getChars());
|
||||
}
|
||||
|
||||
public PBESecretKeyDecryptor getPBESecretKeyDecryptor(Passphrase passphrase) throws PGPException {
|
||||
return new JcePBESecretKeyDecryptorBuilder(getPGPDigestCalculatorProvider())
|
||||
.setProvider(ProviderFactory.getProvider())
|
||||
.build(passphrase.getChars());
|
||||
}
|
||||
|
||||
public PGPDigestCalculatorProvider getPGPDigestCalculatorProvider()
|
||||
throws PGPException {
|
||||
return new JcaPGPDigestCalculatorProviderBuilder()
|
||||
.setProvider(ProviderFactory.getProvider())
|
||||
.build();
|
||||
}
|
||||
|
||||
public PGPContentVerifierBuilderProvider getPGPContentVerifierBuilderProvider() {
|
||||
return new JcaPGPContentVerifierBuilderProvider()
|
||||
.setProvider(ProviderFactory.getProvider());
|
||||
}
|
||||
|
||||
public PGPContentSignerBuilder getPGPContentSignerBuilder(int keyAlgorithm, int hashAlgorithm) {
|
||||
return new JcaPGPContentSignerBuilder(keyAlgorithm, hashAlgorithm)
|
||||
.setProvider(ProviderFactory.getProvider());
|
||||
}
|
||||
|
||||
public KeyFingerPrintCalculator getKeyFingerprintCalculator() {
|
||||
return new JcaKeyFingerprintCalculator()
|
||||
.setProvider(ProviderFactory.getProvider());
|
||||
}
|
||||
|
||||
public PBEDataDecryptorFactory getPBEDataDecryptorFactory(Passphrase passphrase)
|
||||
throws PGPException {
|
||||
return new JcePBEDataDecryptorFactoryBuilder(getPGPDigestCalculatorProvider())
|
||||
.setProvider(ProviderFactory.getProvider())
|
||||
.build(passphrase.getChars());
|
||||
}
|
||||
|
||||
public PublicKeyDataDecryptorFactory getPublicKeyDataDecryptorFactory(PGPPrivateKey privateKey) {
|
||||
return new JcePublicKeyDataDecryptorFactoryBuilder()
|
||||
.setProvider(ProviderFactory.getProvider())
|
||||
.build(privateKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SessionKeyDataDecryptorFactory getSessionKeyDataDecryptorFactory(PGPSessionKey sessionKey) {
|
||||
return new JceSessionKeyDataDecryptorFactoryBuilder()
|
||||
.build(sessionKey);
|
||||
}
|
||||
|
||||
public PublicKeyKeyEncryptionMethodGenerator getPublicKeyKeyEncryptionMethodGenerator(PGPPublicKey key) {
|
||||
return new JcePublicKeyKeyEncryptionMethodGenerator(key)
|
||||
.setProvider(ProviderFactory.getProvider());
|
||||
}
|
||||
|
||||
public PBEKeyEncryptionMethodGenerator getPBEKeyEncryptionMethodGenerator(Passphrase passphrase) {
|
||||
return new JcePBEKeyEncryptionMethodGenerator(passphrase.getChars())
|
||||
.setProvider(ProviderFactory.getProvider());
|
||||
}
|
||||
|
||||
public PGPDataEncryptorBuilder getPGPDataEncryptorBuilder(int symmetricKeyAlgorithm) {
|
||||
return new JcePGPDataEncryptorBuilder(symmetricKeyAlgorithm)
|
||||
.setProvider(ProviderFactory.getProvider());
|
||||
}
|
||||
|
||||
public PGPKeyPair getPGPKeyPair(PublicKeyAlgorithm algorithm, KeyPair keyPair, Date creationDate) throws PGPException {
|
||||
return new JcaPGPKeyPair(algorithm.getAlgorithmId(), keyPair, creationDate);
|
||||
}
|
||||
|
||||
public PBESecretKeyEncryptor getPBESecretKeyEncryptor(SymmetricKeyAlgorithm encryptionAlgorithm, HashAlgorithm hashAlgorithm, int s2kCount, Passphrase passphrase) throws PGPException {
|
||||
return new JcePBESecretKeyEncryptorBuilder(
|
||||
encryptionAlgorithm.getAlgorithmId(),
|
||||
getPGPDigestCalculator(hashAlgorithm),
|
||||
s2kCount)
|
||||
.setProvider(ProviderFactory.getProvider())
|
||||
.build(passphrase.getChars());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PGPObjectFactory getPGPObjectFactory(InputStream inputStream) {
|
||||
return new PGPObjectFactory(inputStream, ImplementationFactory.getInstance().getKeyFingerprintCalculator());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PGPObjectFactory getPGPObjectFactory(byte[] bytes) {
|
||||
return new PGPObjectFactory(bytes, ImplementationFactory.getInstance().getKeyFingerprintCalculator());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2020 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/**
|
||||
* Implementation factory classes to be able to switch out the underlying crypto engine implementation.
|
||||
*/
|
||||
package org.pgpainless.implementation;
|
||||
|
|
@ -120,7 +120,7 @@ public class PublicKeyParameterValidationUtil {
|
|||
signatureGenerator.update(data);
|
||||
PGPSignature sig = signatureGenerator.generate();
|
||||
|
||||
sig.init(ImplementationFactory.getInstance().getPGPContentVerifierBuilderProvider(), publicKey);
|
||||
sig.init(ImplementationFactory.getInstance().getPgpContentVerifierBuilderProvider(), publicKey);
|
||||
sig.update(data);
|
||||
return sig.verify();
|
||||
} catch (PGPException e) {
|
||||
|
|
|
|||
|
|
@ -495,7 +495,7 @@ public abstract class SignatureValidator {
|
|||
}
|
||||
try {
|
||||
signature.init(ImplementationFactory.getInstance()
|
||||
.getPGPContentVerifierBuilderProvider(), primaryKey);
|
||||
.getPgpContentVerifierBuilderProvider(), primaryKey);
|
||||
boolean valid = signature.verifyCertification(primaryKey, subkey);
|
||||
if (!valid) {
|
||||
throw new SignatureValidationException("Signature is not correct.");
|
||||
|
|
@ -519,7 +519,7 @@ public abstract class SignatureValidator {
|
|||
@Override
|
||||
public void verify(PGPSignature signature) throws SignatureValidationException {
|
||||
try {
|
||||
signature.init(ImplementationFactory.getInstance().getPGPContentVerifierBuilderProvider(), subkey);
|
||||
signature.init(ImplementationFactory.getInstance().getPgpContentVerifierBuilderProvider(), subkey);
|
||||
boolean valid = signature.verifyCertification(primaryKey, subkey);
|
||||
if (!valid) {
|
||||
throw new SignatureValidationException("Primary Key Binding Signature is not correct.");
|
||||
|
|
@ -544,7 +544,7 @@ public abstract class SignatureValidator {
|
|||
@Override
|
||||
public void verify(PGPSignature signature) throws SignatureValidationException {
|
||||
try {
|
||||
signature.init(ImplementationFactory.getInstance().getPGPContentVerifierBuilderProvider(), signer);
|
||||
signature.init(ImplementationFactory.getInstance().getPgpContentVerifierBuilderProvider(), signer);
|
||||
boolean valid;
|
||||
if (signer.getKeyID() == signee.getKeyID() || signature.getSignatureType() == PGPSignature.DIRECT_KEY) {
|
||||
valid = signature.verifyCertification(signee);
|
||||
|
|
@ -615,7 +615,7 @@ public abstract class SignatureValidator {
|
|||
public void verify(PGPSignature signature) throws SignatureValidationException {
|
||||
try {
|
||||
signature.init(ImplementationFactory.getInstance()
|
||||
.getPGPContentVerifierBuilderProvider(), certifyingKey);
|
||||
.getPgpContentVerifierBuilderProvider(), certifyingKey);
|
||||
boolean valid = signature.verifyCertification(userId, certifiedKey);
|
||||
if (!valid) {
|
||||
throw new SignatureValidationException("Signature over user-id '" + userId +
|
||||
|
|
@ -645,7 +645,7 @@ public abstract class SignatureValidator {
|
|||
public void verify(PGPSignature signature) throws SignatureValidationException {
|
||||
try {
|
||||
signature.init(ImplementationFactory.getInstance()
|
||||
.getPGPContentVerifierBuilderProvider(), certifyingKey);
|
||||
.getPgpContentVerifierBuilderProvider(), certifyingKey);
|
||||
boolean valid = signature.verifyCertification(userAttributes, certifiedKey);
|
||||
if (!valid) {
|
||||
throw new SignatureValidationException("Signature over user-attribute vector is not correct.");
|
||||
|
|
|
|||
|
|
@ -384,7 +384,7 @@ public final class SignatureVerifier {
|
|||
PGPPublicKey signingKey)
|
||||
throws SignatureValidationException {
|
||||
try {
|
||||
signature.init(ImplementationFactory.getInstance().getPGPContentVerifierBuilderProvider(), signingKey);
|
||||
signature.init(ImplementationFactory.getInstance().getPgpContentVerifierBuilderProvider(), signingKey);
|
||||
int read;
|
||||
byte[] buf = new byte[8192];
|
||||
byte lastByte = -1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue