Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bouncycastle.jcajce.provider.asymmetric.rsa;
  
 
 
 public class PSSSignatureSpi
     extends SignatureSpi
 {
     private final JcaJceHelper helper = new BCJcaJceHelper();
 
     private AlgorithmParameters engineParams;
     private PSSParameterSpec paramSpec;
     private PSSParameterSpec originalSpec;
     private AsymmetricBlockCipher signer;
     private Digest contentDigest;
     private Digest mgfDigest;
     private int saltLength;
     private byte trailer;
     private boolean isRaw;
 
 
     private byte getTrailer(
         int trailerField)
     {
         if (trailerField == 1)
         {
             return .....;
         }
         
         throw new IllegalArgumentException("unknown trailer field");
     }
 
     private void setupContentDigest()
     {
         if ()
         {
             this. = new NullPssDigest();
         }
         else
         {
             this. = ;
         }
     }
 
     // care - this constructor is actually used by outside organisations
     protected PSSSignatureSpi(
         AsymmetricBlockCipher signer,
         PSSParameterSpec paramSpecArg)
     {
         this(signerparamSpecArgfalse);
     }
 
     // care - this constructor is actually used by outside organisations
     protected PSSSignatureSpi(
         AsymmetricBlockCipher signer,
         PSSParameterSpec baseParamSpec,
         boolean isRaw)
     {
         this. = signer;
         this. = baseParamSpec;
         
         if (baseParamSpec == null)
         {
             this. = .;
         }
         else
         {
             this. = baseParamSpec;
         }
 
         this. = DigestFactory.getDigest(.getDigestAlgorithm());
         this. = .getSaltLength();
         this. = getTrailer(.getTrailerField());
         this. = isRaw;
 
        setupContentDigest();
    }
    
    protected void engineInitVerify(
        PublicKey publicKey)
        throws InvalidKeyException
    {
        if (!(publicKey instanceof RSAPublicKey))
        {
            throw new InvalidKeyException("Supplied key is not a RSAPublicKey instance");
        }
        .init(false,
            RSAUtil.generatePublicKeyParameter((RSAPublicKey)publicKey));
    }
    protected void engineInitSign(
        PrivateKey privateKey,
        SecureRandom random)
        throws InvalidKeyException
    {
        if (!(privateKey instanceof RSAPrivateKey))
        {
            throw new InvalidKeyException("Supplied key is not a RSAPrivateKey instance");
        }
        .init(truenew ParametersWithRandom(RSAUtil.generatePrivateKeyParameter((RSAPrivateKey)privateKey), random));
    }
    protected void engineInitSign(
        PrivateKey privateKey)
        throws InvalidKeyException
    {
        if (!(privateKey instanceof RSAPrivateKey))
        {
            throw new InvalidKeyException("Supplied key is not a RSAPrivateKey instance");
        }
        .init(true, RSAUtil.generatePrivateKeyParameter((RSAPrivateKey)privateKey));
    }
    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
    {
        try
        {
            return .generateSignature();
        }
        catch (CryptoException e)
        {
            throw new SignatureException(e.getMessage());
        }
    }
    protected boolean engineVerify(
        byte[]  sigBytes
        throws SignatureException
    {
        return .verifySignature(sigBytes);
    }
    protected void engineSetParameter(
        AlgorithmParameterSpec params)
        throws InvalidParameterException
    {
        if (params instanceof PSSParameterSpec)
        {
            PSSParameterSpec newParamSpec = (PSSParameterSpec)params;
            
            if ( != null)
            {
                if (!DigestFactory.isSameDigest(.getDigestAlgorithm(), newParamSpec.getDigestAlgorithm()))
                {
                    throw new InvalidParameterException("parameter must be using " + .getDigestAlgorithm());
                }
            }
            if (!newParamSpec.getMGFAlgorithm().equalsIgnoreCase("MGF1") && !newParamSpec.getMGFAlgorithm().equals(..getId()))
            {
                throw new InvalidParameterException("unknown mask generation function specified");
            }
            
            if (!(newParamSpec.getMGFParameters() instanceof MGF1ParameterSpec))
            {
                throw new InvalidParameterException("unkown MGF parameters");
            }
            
            MGF1ParameterSpec mgfParams = (MGF1ParameterSpec)newParamSpec.getMGFParameters();
            
            if (!DigestFactory.isSameDigest(mgfParams.getDigestAlgorithm(), newParamSpec.getDigestAlgorithm()))
            {
                throw new InvalidParameterException("digest algorithm for MGF should be the same as for PSS parameters.");
            }
            
            Digest newDigest = DigestFactory.getDigest(mgfParams.getDigestAlgorithm());
            
            if (newDigest == null)
            {
                throw new InvalidParameterException("no match on MGF digest algorithm: "mgfParams.getDigestAlgorithm());
            }
            this. = null;
            this. = newParamSpec;
            this. = newDigest;
            this. = .getSaltLength();
            this. = getTrailer(.getTrailerField());
            setupContentDigest();
        }
        else
        {
            throw new InvalidParameterException("Only PSSParameterSpec supported");
        }
    }
    {
        if ( == null)
        {
            if ( != null)
            {
                try
                {
                     = .createAlgorithmParameters("PSS");
                    .init();
                }
                catch (Exception e)
                {
                    throw new RuntimeException(e.toString());
                }
            }
        }
        return ;
    }
    
    

Deprecated:
replaced with
    protected void engineSetParameter(
        String param,
        Object value)
    {
        throw new UnsupportedOperationException("engineSetParameter unsupported");
    }
    
    protected Object engineGetParameter(
        String param)
    {
        throw new UnsupportedOperationException("engineGetParameter unsupported");
    }
    static public class nonePSS
        extends PSSSignatureSpi
    {
        public nonePSS()
        {
            super(new RSABlindedEngine(), nulltrue);
        }
    }
    static public class PSSwithRSA
        extends PSSSignatureSpi
    {
        public PSSwithRSA()
        {
            super(new RSABlindedEngine(), null);
        }
    }
    
    static public class SHA1withRSA
        extends PSSSignatureSpi
    {
        public SHA1withRSA()
        {
            super(new RSABlindedEngine(), .);
        }
    }
    static public class SHA224withRSA
        extends PSSSignatureSpi
    {
        public SHA224withRSA()
        {
            super(new RSABlindedEngine(), new PSSParameterSpec("SHA-224""MGF1"new MGF1ParameterSpec("SHA-224"), 28, 1));
        }
    }
    
    static public class SHA256withRSA
        extends PSSSignatureSpi
    {
        public SHA256withRSA()
        {
            super(new RSABlindedEngine(), new PSSParameterSpec("SHA-256""MGF1"new MGF1ParameterSpec("SHA-256"), 32, 1));
        }
    }
    static public class SHA384withRSA
        extends PSSSignatureSpi
    {
        public SHA384withRSA()
        {
            super(new RSABlindedEngine(), new PSSParameterSpec("SHA-384""MGF1"new MGF1ParameterSpec("SHA-384"), 48, 1));
        }
    }
    static public class SHA512withRSA
        extends PSSSignatureSpi
    {
        public SHA512withRSA()
        {
            super(new RSABlindedEngine(), new PSSParameterSpec("SHA-512""MGF1"new MGF1ParameterSpec("SHA-512"), 64, 1));
        }
    }
    private class NullPssDigest
        implements Digest
    {
        private ByteArrayOutputStream bOut = new ByteArrayOutputStream();
        private Digest baseDigest;
        private boolean oddTime = true;
        public NullPssDigest(Digest mgfDigest)
        {
            this. = mgfDigest;
        }
        public String getAlgorithmName()
        {
            return "NULL";
        }
        public int getDigestSize()
        {
            return .getDigestSize();
        }
        public void update(byte in)
        {
            .write(in);
        }
        public void update(byte[] inint inOffint len)
        {
            .write(ininOfflen);
        }
        public int doFinal(byte[] outint outOff)
        {
            byte[] res = .toByteArray();
            if ()
            {
                System.arraycopy(res, 0, outoutOffres.length);
            }
            else
            {
                .update(res, 0, res.length);
                .doFinal(outoutOff);
            }
            reset();
             = !;
            return res.length;
        }
        public void reset()
        {
            .reset();
            .reset();
        }
        public int getByteLength()
        {
            return 0;
        }
    }
New to GrepCode? Check out our FAQ X