blob: a2cfbf911f3729818f80d86694f8ea4ad3290f35 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
package org.spongycastle.openpgp.operator.bc;
import java.io.OutputStream;
import org.spongycastle.crypto.Signer;
import org.spongycastle.openpgp.PGPException;
import org.spongycastle.openpgp.PGPPublicKey;
import org.spongycastle.openpgp.operator.PGPContentVerifier;
import org.spongycastle.openpgp.operator.PGPContentVerifierBuilder;
import org.spongycastle.openpgp.operator.PGPContentVerifierBuilderProvider;
public class BcPGPContentVerifierBuilderProvider
implements PGPContentVerifierBuilderProvider
{
private BcPGPKeyConverter keyConverter = new BcPGPKeyConverter();
public BcPGPContentVerifierBuilderProvider()
{
}
public PGPContentVerifierBuilder get(int keyAlgorithm, int hashAlgorithm)
throws PGPException
{
return new BcPGPContentVerifierBuilder(keyAlgorithm, hashAlgorithm);
}
private class BcPGPContentVerifierBuilder
implements PGPContentVerifierBuilder
{
private int hashAlgorithm;
private int keyAlgorithm;
public BcPGPContentVerifierBuilder(int keyAlgorithm, int hashAlgorithm)
{
this.keyAlgorithm = keyAlgorithm;
this.hashAlgorithm = hashAlgorithm;
}
public PGPContentVerifier build(final PGPPublicKey publicKey)
throws PGPException
{
final Signer signer = BcImplProvider.createSigner(keyAlgorithm, hashAlgorithm);
signer.init(false, keyConverter.getPublicKey(publicKey));
return new PGPContentVerifier()
{
public int getHashAlgorithm()
{
return hashAlgorithm;
}
public int getKeyAlgorithm()
{
return keyAlgorithm;
}
public long getKeyID()
{
return publicKey.getKeyID();
}
public boolean verify(byte[] expected)
{
return signer.verifySignature(expected);
}
public OutputStream getOutputStream()
{
return new SignerOutputStream(signer);
}
};
}
}
}
|