Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bouncycastle.jcajce.provider.asymmetric.dsa;
  
 
 
 public class DSASigner
     extends SignatureSpi
 {
     private Digest                  digest;
     private DSA                     signer;
     private SecureRandom            random;
 
     protected DSASigner(
         Digest digest,
         DSA signer)
     {
         this. = digest;
         this. = signer;
     }
 
     protected void engineInitVerify(
         PublicKey   publicKey)
         throws InvalidKeyException
     {
         CipherParameters    param;
 
         if (publicKey instanceof DSAKey)
         {
             param = DSAUtil.generatePublicKeyParameter(publicKey);
         }
         else
         {
             try
             {
                 byte[]  bytes = publicKey.getEncoded();
 
                 publicKey = new BCDSAPublicKey(SubjectPublicKeyInfo.getInstance(bytes));
 
                 if (publicKey instanceof DSAKey)
                 {
                     param = DSAUtil.generatePublicKeyParameter(publicKey);
                 }
                 else
                 {
                     throw new InvalidKeyException("can't recognise key type in DSA based signer");
                 }
             }
             catch (Exception e)
             {
                 throw new InvalidKeyException("can't recognise key type in DSA based signer");
             }
         }
 
         .reset();
         .init(falseparam);
     }
 
     protected void engineInitSign(
         PrivateKey      privateKey,
         SecureRandom    random)
         throws InvalidKeyException
     {
         this. = random;
         engineInitSign(privateKey);
     }
 
     protected void engineInitSign(
         PrivateKey  privateKey)
         throws InvalidKeyException
     {
        CipherParameters    param;
        param = DSAUtil.generatePrivateKeyParameter(privateKey);
        if ( != null)
        {
            param = new ParametersWithRandom(param);
        }
        .reset();
        .init(trueparam);
    }
    protected void engineUpdate(
        byte    b)
        throws SignatureException
    {
        .update(b);
    }
    protected void engineUpdate(
        byte[]  b,
        int     off,
        int     len
        throws SignatureException
    {
        .update(bofflen);
    }
    protected byte[] engineSign()
        throws SignatureException
    {
        byte[]  hash = new byte[.getDigestSize()];
        .doFinal(hash, 0);
        try
        {
            BigInteger[]    sig = .generateSignature(hash);
            return derEncode(sig[0], sig[1]);
        }
        catch (Exception e)
        {
            throw new SignatureException(e.toString());
        }
    }
    protected boolean engineVerify(
        byte[]  sigBytes
        throws SignatureException
    {
        byte[]  hash = new byte[.getDigestSize()];
        .doFinal(hash, 0);
        BigInteger[]    sig;
        try
        {
            sig = derDecode(sigBytes);
        }
        catch (Exception e)
        {
            throw new SignatureException("error decoding signature bytes.");
        }
        return .verifySignature(hashsig[0], sig[1]);
    }
    protected void engineSetParameter(
        AlgorithmParameterSpec params)
    {
        throw new UnsupportedOperationException("engineSetParameter unsupported");
    }

    

Deprecated:
replaced with
    protected void engineSetParameter(
        String  param,
        Object  value)
    {
        throw new UnsupportedOperationException("engineSetParameter unsupported");
    }

    

Deprecated:
    protected Object engineGetParameter(
        String      param)
    {
        throw new UnsupportedOperationException("engineSetParameter unsupported");
    }
    private byte[] derEncode(
        BigInteger  r,
        BigInteger  s)
        throws IOException
    {
        ASN1Integer[] rs = new ASN1Integer[]{ new ASN1Integer(r), new ASN1Integer(s) };
        return new DERSequence(rs).getEncoded(.);
    }
    private BigInteger[] derDecode(
        byte[]  encoding)
        throws IOException
    {
        ASN1Sequence s = (ASN1Sequence)ASN1Primitive.fromByteArray(encoding);
        return new BigInteger[]{
            ((ASN1Integer)s.getObjectAt(0)).getValue(),
            ((ASN1Integer)s.getObjectAt(1)).getValue()
        };
    }
    static public class stdDSA
        extends DSASigner
    {
        public stdDSA()
        {
            super(new SHA1Digest(), new org.bouncycastle.crypto.signers.DSASigner());
        }
    }
    static public class detDSA
        extends DSASigner
    {
        public detDSA()
        {
            super(new SHA1Digest(), new org.bouncycastle.crypto.signers.DSASigner(new HMacDSAKCalculator(new SHA1Digest())));
        }
    }
    static public class dsa224
        extends DSASigner
    {
        public dsa224()
        {
            super(new SHA224Digest(), new org.bouncycastle.crypto.signers.DSASigner());
        }
    }
    static public class detDSA224
        extends DSASigner
    {
        public detDSA224()
        {
            super(new SHA224Digest(), new org.bouncycastle.crypto.signers.DSASigner(new HMacDSAKCalculator(new SHA224Digest())));
        }
    }
    static public class dsa256
        extends DSASigner
    {
        public dsa256()
        {
            super(new SHA256Digest(), new org.bouncycastle.crypto.signers.DSASigner());
        }
    }
    static public class detDSA256
        extends DSASigner
    {
        public detDSA256()
        {
            super(new SHA256Digest(), new org.bouncycastle.crypto.signers.DSASigner(new HMacDSAKCalculator(new SHA256Digest())));
        }
    }
    static public class dsa384
        extends DSASigner
    {
        public dsa384()
        {
            super(new SHA384Digest(), new org.bouncycastle.crypto.signers.DSASigner());
        }
    }
    static public class detDSA384
        extends DSASigner
    {
        public detDSA384()
        {
            super(new SHA384Digest(), new org.bouncycastle.crypto.signers.DSASigner(new HMacDSAKCalculator(new SHA384Digest())));
        }
    }
    static public class dsa512
        extends DSASigner
    {
        public dsa512()
        {
            super(new SHA512Digest(), new org.bouncycastle.crypto.signers.DSASigner());
        }
    }
    static public class detDSA512
        extends DSASigner
    {
        public detDSA512()
        {
            super(new SHA512Digest(), new org.bouncycastle.crypto.signers.DSASigner(new HMacDSAKCalculator(new SHA512Digest())));
        }
    }
    static public class noneDSA
        extends DSASigner
    {
        public noneDSA()
        {
            super(new NullDigest(), new org.bouncycastle.crypto.signers.DSASigner());
        }
    }
New to GrepCode? Check out our FAQ X