mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-09 18:29:39 +02:00
Port CanonicalizedDataEncryptionTest
This commit is contained in:
parent
c9b80315ed
commit
bab6357e76
1 changed files with 11 additions and 11 deletions
|
@ -22,11 +22,10 @@ import org.bouncycastle.openpgp.PGPException;
|
|||
import org.bouncycastle.openpgp.PGPLiteralData;
|
||||
import org.bouncycastle.openpgp.PGPLiteralDataGenerator;
|
||||
import org.bouncycastle.openpgp.PGPOnePassSignature;
|
||||
import org.bouncycastle.openpgp.PGPPrivateKey;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.bouncycastle.openpgp.PGPSignatureGenerator;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPCertificate;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPKey;
|
||||
import org.bouncycastle.openpgp.operator.bc.BcPGPContentSignerBuilder;
|
||||
import org.bouncycastle.util.io.Streams;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
|
@ -109,13 +108,13 @@ public class CanonicalizedDataEncryptionTest {
|
|||
|
||||
String message = "Hello, World!\n";
|
||||
|
||||
private static PGPSecretKeyRing secretKeys;
|
||||
private static PGPPublicKeyRing publicKeys;
|
||||
private static OpenPGPKey secretKeys;
|
||||
private static OpenPGPCertificate publicKeys;
|
||||
|
||||
@BeforeAll
|
||||
public static void readKeys() throws IOException {
|
||||
secretKeys = PGPainless.readKeyRing().secretKeyRing(KEY);
|
||||
publicKeys = PGPainless.extractCertificate(secretKeys);
|
||||
secretKeys = PGPainless.getInstance().readKey().parseKey(KEY);
|
||||
publicKeys = secretKeys.toCertificate();
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println(PGPainless.asciiArmor(secretKeys));
|
||||
// CHECKSTYLE:ON
|
||||
|
@ -397,7 +396,7 @@ public class CanonicalizedDataEncryptionTest {
|
|||
|
||||
public void manualSignAndVerify(DocumentSignatureType sigType, StreamEncoding streamEncoding)
|
||||
throws IOException, PGPException {
|
||||
PGPPrivateKey privateKey = UnlockSecretKey.unlockSecretKey(secretKeys.getSecretKey(), SecretKeyRingProtector.unprotectedKeys());
|
||||
OpenPGPKey.OpenPGPPrivateKey privateKey = UnlockSecretKey.unlockSecretKey(secretKeys.getPrimarySecretKey(), SecretKeyRingProtector.unprotectedKeys());
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ArmoredOutputStream armorOut = new ArmoredOutputStream(out);
|
||||
|
||||
|
@ -406,9 +405,10 @@ public class CanonicalizedDataEncryptionTest {
|
|||
|
||||
PGPSignatureGenerator signer = new PGPSignatureGenerator(
|
||||
new BcPGPContentSignerBuilder(
|
||||
secretKeys.getPublicKey().getAlgorithm(),
|
||||
HashAlgorithm.SHA256.getAlgorithmId()));
|
||||
signer.init(sigType.getSignatureType().getCode(), privateKey);
|
||||
secretKeys.getPrimaryKey().getPGPPublicKey().getAlgorithm(),
|
||||
HashAlgorithm.SHA256.getAlgorithmId()),
|
||||
secretKeys.getPrimaryKey().getPGPPublicKey());
|
||||
signer.init(sigType.getSignatureType().getCode(), privateKey.getKeyPair().getPrivateKey());
|
||||
|
||||
PGPOnePassSignature ops = signer.generateOnePassVersion(false);
|
||||
ops.encode(compressedOut);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue