mirror of
https://codeberg.org/PGPainless/bc-sop.git
synced 2025-09-09 03:09:40 +02:00
Adjust to latest changes (fa281a744d537f9d369b92ee02c7f7cb61c2ee6f)
This commit is contained in:
parent
994ba47b30
commit
ec4bb0c5db
4 changed files with 31 additions and 7 deletions
|
@ -3,9 +3,12 @@ package org.pgpainless.bouncycastle.sop.operation;
|
|||
import org.bouncycastle.bcpg.ArmoredOutputStream;
|
||||
import org.bouncycastle.bcpg.BCPGOutputStream;
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPApi;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPDetachedSignatureGenerator;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPKey;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPSignature;
|
||||
import org.bouncycastle.openpgp.api.SignatureParameters;
|
||||
import org.bouncycastle.openpgp.api.exception.InvalidSigningKeyException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import sop.MicAlg;
|
||||
|
@ -28,6 +31,8 @@ public class BCDetachedSign
|
|||
private boolean armored = true;
|
||||
private char[] keyPassword = null;
|
||||
|
||||
private int signatureMode = PGPSignature.BINARY_DOCUMENT;
|
||||
|
||||
public BCDetachedSign(OpenPGPApi api) {
|
||||
super(api);
|
||||
sigGen = api.createDetachedSignature();
|
||||
|
@ -83,10 +88,10 @@ public class BCDetachedSign
|
|||
switch (signAs)
|
||||
{
|
||||
case text:
|
||||
sigGen.setCanonicalTextDocument();
|
||||
signatureMode = PGPSignature.CANONICAL_TEXT_DOCUMENT;
|
||||
break;
|
||||
case binary:
|
||||
sigGen.setBinarySignature();
|
||||
signatureMode = PGPSignature.BINARY_DOCUMENT;
|
||||
break;
|
||||
}
|
||||
return this;
|
||||
|
@ -102,7 +107,16 @@ public class BCDetachedSign
|
|||
public DetachedSign key(@NotNull InputStream inputStream) throws SOPGPException.KeyCannotSign, SOPGPException.BadData, SOPGPException.UnsupportedAsymmetricAlgo, IOException {
|
||||
try
|
||||
{
|
||||
sigGen.addSigningKey(parseKey(inputStream), keyPassword);
|
||||
OpenPGPKey key = parseKey(inputStream);
|
||||
OpenPGPKey.OpenPGPSecretKey signingKey = key.getSecretKey(key.getSigningKeys().get(0));
|
||||
sigGen.addSigningKey(signingKey,
|
||||
k -> keyPassword,
|
||||
new SignatureParameters.Callback() {
|
||||
@Override
|
||||
public SignatureParameters apply(SignatureParameters parameters) {
|
||||
return parameters.setSignatureType(signatureMode);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (InvalidSigningKeyException e)
|
||||
{
|
||||
|
|
|
@ -5,6 +5,7 @@ import org.bouncycastle.openpgp.api.OpenPGPApi;
|
|||
import org.bouncycastle.openpgp.api.OpenPGPMessageGenerator;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPMessageOutputStream;
|
||||
import org.bouncycastle.openpgp.api.exception.InvalidEncryptionKeyException;
|
||||
import org.bouncycastle.openpgp.api.exception.InvalidSigningKeyException;
|
||||
import org.bouncycastle.util.io.Streams;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import sop.EncryptionResult;
|
||||
|
@ -46,7 +47,11 @@ public class BCEncrypt
|
|||
@NotNull
|
||||
@Override
|
||||
public Encrypt signWith(@NotNull InputStream inputStream) throws SOPGPException.KeyCannotSign, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.BadData, IOException {
|
||||
try {
|
||||
mGen.addSigningKey(parseKey(inputStream), k -> keyPassword);
|
||||
} catch (InvalidSigningKeyException e) {
|
||||
throw new SOPGPException.KeyCannotSign("Key cannot sign", e);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,11 +46,11 @@ public class BCGenerateKey
|
|||
{
|
||||
if (signOnly)
|
||||
{
|
||||
key = generator.signOnlyKey(passphrase);
|
||||
key = generator.signOnlyKey().build(passphrase);
|
||||
}
|
||||
else
|
||||
{
|
||||
key = generator.ed25519x25519Key(userId, passphrase);
|
||||
key = generator.ed25519x25519Key(userId).build(passphrase);
|
||||
}
|
||||
}
|
||||
catch (PGPException e)
|
||||
|
|
|
@ -4,6 +4,7 @@ import org.bouncycastle.openpgp.PGPException;
|
|||
import org.bouncycastle.openpgp.api.OpenPGPApi;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPMessageGenerator;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPMessageOutputStream;
|
||||
import org.bouncycastle.openpgp.api.exception.InvalidSigningKeyException;
|
||||
import org.bouncycastle.util.io.Streams;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import sop.Ready;
|
||||
|
@ -59,7 +60,11 @@ public class BCInlineSign
|
|||
|
||||
@Override
|
||||
public InlineSign key(@NotNull InputStream inputStream) throws SOPGPException.KeyCannotSign, SOPGPException.BadData, SOPGPException.UnsupportedAsymmetricAlgo, IOException {
|
||||
try {
|
||||
mGen.addSigningKey(api.readKeyOrCertificate().parseKey(inputStream), k -> keyPassword);
|
||||
} catch (InvalidSigningKeyException e) {
|
||||
throw new SOPGPException.KeyCannotSign("Key cannot sign.", e);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue