rsaengine.java

来自「kmlnjlkj nlkjlkjkljl okopokipoipo oipipi」· Java 代码 · 共 79 行

JAVA
79
字号
package org.bouncycastle.crypto.engines;import org.bouncycastle.crypto.AsymmetricBlockCipher;import org.bouncycastle.crypto.CipherParameters;import org.bouncycastle.crypto.DataLengthException;/** * this does your basic RSA algorithm. */public class RSAEngine    implements AsymmetricBlockCipher{    private RSACoreEngine core;    /**     * initialise the RSA engine.     *     * @param forEncryption true if we are encrypting, false otherwise.     * @param param the necessary RSA key parameters.     */    public void init(        boolean             forEncryption,        CipherParameters    param)    {        if (core == null)        {            core = new RSACoreEngine();        }        core.init(forEncryption, param);    }    /**     * 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.     *     * @return maximum size for an input block.     */    public int getInputBlockSize()    {        return core.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.     *     * @return maximum size for an output block.     */    public int getOutputBlockSize()    {        return core.getOutputBlockSize();    }    /**     * Process a single block using the basic RSA algorithm.     *     * @param in the input array.     * @param inOff the offset into the input buffer where the data starts.     * @param inLen the length of the data to be processed.     * @return the result of the RSA process.     * @exception DataLengthException the input block is too large.     */    public byte[] processBlock(        byte[]  in,        int     inOff,        int     inLen)    {        if (core == null)        {            throw new IllegalStateException("RSA engine not initialised");        }        return core.convertOutput(core.processBlock(core.convertInput(in, inOff, inLen)));    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?