Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bouncycastle.crypto.engines;
  
  
This does your basic RSA Chaum's blinding and unblinding as outlined in "Handbook of Applied Cryptography", page 475. You need to use this if you are trying to get another party to generate signatures without them being aware of the message they are signing.
 
 public class RSABlindingEngine
     implements AsymmetricBlockCipher
 {
     private RSACoreEngine core = new RSACoreEngine();
 
     private RSAKeyParameters key;
     private BigInteger blindingFactor;
 
     private boolean forEncryption;

    
Initialise the blinding engine.

Parameters:
forEncryption true if we are encrypting (blinding), false otherwise.
param the necessary RSA key parameters.
 
     public void init(
         boolean forEncryption,
         CipherParameters param)
     {
         RSABlindingParameters p;
 
         if (param instanceof ParametersWithRandom)
         {
             ParametersWithRandom rParam = (ParametersWithRandom)param;
 
             p = (RSABlindingParameters)rParam.getParameters();
         }
         else
         {
             p = (RSABlindingParameters)param;
         }
 
         .init(forEncryptionp.getPublicKey());
 
         this. = forEncryption;
         this. = p.getPublicKey();
         this. = p.getBlindingFactor();
     }

    
Return the maximum size for an input block to this engine. For RSA this is always one byte less than the key size on encryption, and the same length as the key size on decryption.

Returns:
maximum size for an input block.
 
     public int getInputBlockSize()
     {
         return .getInputBlockSize();
     }

    
Return the maximum size for an output block to this engine. For RSA this is always one byte less than the key size on decryption, and the same length as the key size on encryption.

Returns:
maximum size for an output block.
 
     public int getOutputBlockSize()
     {
         return .getOutputBlockSize();
     }

    
Process a single block using the RSA blinding algorithm.

Parameters:
in the input array.
inOff the offset into the input buffer where the data starts.
inLen the length of the data to be processed.
Returns:
the result of the RSA process.
Throws:
org.bouncycastle.crypto.DataLengthException the input block is too large.
 
     public byte[] processBlock(
         byte[] in,
         int inOff,
         int inLen)
     {
         BigInteger msg = .convertInput(ininOffinLen);
 
         if ()
         {
            msg = blindMessage(msg);
        }
        else
        {
            msg = unblindMessage(msg);
        }
        return .convertOutput(msg);
    }
    /*
     * Blind message with the blind factor.
     */
    private BigInteger blindMessage(
        BigInteger msg)
    {
        BigInteger blindMsg = ;
        blindMsg = msg.multiply(blindMsg.modPow(.getExponent(), .getModulus()));
        blindMsg = blindMsg.mod(.getModulus());
        return blindMsg;
    }
    /*
     * Unblind the message blinded with the blind factor.
     */
    private BigInteger unblindMessage(
        BigInteger blindedMsg)
    {
        BigInteger m = .getModulus();
        BigInteger msg = blindedMsg;
        BigInteger blindFactorInverse = .modInverse(m);
        msg = msg.multiply(blindFactorInverse);
        msg = msg.mod(m);
        return msg;
    }
New to GrepCode? Check out our FAQ X