Search in sources :

Example 96 with Signature

use of com.github.zhenwei.core.asn1.ocsp.Signature in project LinLong-Java by zhenwei1108.

the class StandardDSAEncoding method decode.

public BigInteger[] decode(BigInteger n, byte[] encoding) throws IOException {
    ASN1Sequence seq = (ASN1Sequence) ASN1Primitive.fromByteArray(encoding);
    if (seq.size() == 2) {
        BigInteger r = decodeValue(n, seq, 0);
        BigInteger s = decodeValue(n, seq, 1);
        byte[] expectedEncoding = encode(n, r, s);
        if (Arrays.areEqual(expectedEncoding, encoding)) {
            return new BigInteger[] { r, s };
        }
    }
    throw new IllegalArgumentException("Malformed signature");
}
Also used : ASN1Sequence(com.github.zhenwei.core.asn1.ASN1Sequence) BigInteger(java.math.BigInteger)

Aggregations

IOException (java.io.IOException)44 ASN1EncodableVector (com.github.zhenwei.core.asn1.ASN1EncodableVector)34 DERSequence (com.github.zhenwei.core.asn1.DERSequence)29 DERBitString (com.github.zhenwei.core.asn1.DERBitString)21 AlgorithmIdentifier (com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)20 OutputStream (java.io.OutputStream)20 SignatureException (java.security.SignatureException)20 GeneralSecurityException (java.security.GeneralSecurityException)15 Signature (java.security.Signature)15 ASN1ObjectIdentifier (com.github.zhenwei.core.asn1.ASN1ObjectIdentifier)14 DEROctetString (com.github.zhenwei.core.asn1.DEROctetString)14 InvalidKeyException (java.security.InvalidKeyException)13 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)13 Iterator (java.util.Iterator)13 OperatorCreationException (com.github.zhenwei.pkix.operator.OperatorCreationException)11 CertificateEncodingException (java.security.cert.CertificateEncodingException)11 NoSuchProviderException (java.security.NoSuchProviderException)10 ASN1OctetString (com.github.zhenwei.core.asn1.ASN1OctetString)9 ASN1Sequence (com.github.zhenwei.core.asn1.ASN1Sequence)9 List (java.util.List)9