Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * See the NOTICE file distributed with this work for additional
   * information regarding copyright ownership.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
   * the License, or (at your option) any later version.
   *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package org.xwiki.crypto.signer.internal;
 
 
Bouncy Castle based signer.

Version:
$Id: 8bfc9a6c2ad5092fae8ce2c69cfde7569a75c933 $
Since:
5.4RC1
 
 {
    
The underlying signer.
 
     protected final Signer signer;

    
The underlying signer.
 
     protected final String signerAlgorithm;

    
True if the signer is initialized for signing.
 
     protected final boolean forSigning;

    
Algorithm identifier of this signer ASN.1 encoded.
 
     protected AlgorithmIdentifier signerAlgorithmIdentifier;

    
Generic Bouncy Castle based signer.

Parameters:
signer the signer to encapsulate.
forSigning true if the signer is setup for signing.
parameters parameters to initialize the cipher.
signerAlgorithm the name of the algorithm implemented by this signer.
signerAlgId the algorithm identifier of the algorithm implemented by this signer.
 
     public BcSigner(Signer signerboolean forSigningCipherParameters parameters,
         String signerAlgorithmAlgorithmIdentifier signerAlgId)
     {
         this. = signer;
         this. = signerAlgorithm;
         this. = forSigning;
         this. = signerAlgId;
         signer.init(forSigningparameters);
     }
 
     @Override
     public String getAlgorithmName()
     {
         return ;
     }
 
     @Override
     {
         return ;
     }
 
     @Override
     public boolean isForSigning()
     {
         return ;
     }
 
     @Override
     {
         .reset();
         return new SignerInputStream(is);
    }
    @Override
    public OutputStream getOutputStream()
    {
        .reset();
        return new SignerOutputStream();
    }
    @Override
    public void update(byte input)
    {
        .update(input);
    }
    @Override
    public void update(byte[] input)
    {
        .update(input, 0, input.length);
    }
    @Override
    public void update(byte[] inputint inputOffsetint inputLen)
    {
        .update(inputinputOffsetinputLen);
    }
    @Override
    public byte[] generate() throws GeneralSecurityException
    {
        try {
            return .generateSignature();
        } catch (CryptoException e) {
            throw new SignatureException(e);
        }
    }
    @Override
    public byte[] generate(byte[] inputthrows GeneralSecurityException
    {
        update(input);
        return generate();
    }
    @Override
    public byte[] generate(byte[] inputint inputOffsetint inputLenthrows GeneralSecurityException
    {
        update(inputinputOffsetinputLen);
        return generate();
    }

    

Since:
6.0M1
    @Override
    public byte[] getSignature()
    {
        try
        {
            return generate();
        } catch (GeneralSecurityException e)
        {
            throw new RuntimeOperatorException("exception obtaining signature: " + e.getMessage(), e);
        }
    }
    @Override
    public boolean verify(byte[] signature)
    {
        return .verifySignature(signature);
    }
    @Override
    public boolean verify(byte[] signaturebyte[] inputthrows GeneralSecurityException
    {
        update(input);
        return verify(signature);
    }
    @Override
    public boolean verify(byte[] signatureint signOffsetint signLenbyte[] inputint inputOffsetint inputLen)
        throws GeneralSecurityException
    {
        update(inputinputOffsetinputLen);
        if (signOffset != 0 || signLen != signature.length) {
            byte[] sign = new byte[signLen];
            System.arraycopy(signaturesignOffsetsign, 0, signLen);
            return verify(sign);
        }
        return verify(signature);
    }
    @Override
    public byte[] getEncoded()
    {
        try {
            return .getEncoded();
        } catch (IOException e) {
            // Very unlikely to happen
            return null;
        }
    }
New to GrepCode? Check out our FAQ X