Bouncycastle RSA密钥大小和填充

时间:2012-07-30 08:16:32

标签: java encryption rsa bouncycastle

我正在使用Bouncycastle的RSA实现。我正在使用以下选项获得密码实例,

"RSA/ECB/PKCS1Padding"

我的问题是你如何选择使用哪种填充?我可以加密的最大数据量是多少? AFAIK RSA有限制。我也找不到欧洲央行的立场?

1 个答案:

答案 0 :(得分:0)

在rsa中,忽略加密模式。如果您有大的加密日期,请自行计算块数,下面的示例可能会对您有所帮助:

        byte[] var21;
        try {

            Cipher cp = Cipher.getInstance("RSA/ECB/PKCS1Padding", new BouncyCastleProvider());
            cp.init(mode, key);
            int blockSize = cp.getBlockSize();
            int blocksNum = (int) Math.ceil((double) data.length / (double) blockSize);
            int calcSize = blockSize;
            Object buffer = null;
            outputStream = new ByteArrayOutputStream();
            for (int i = 0; i < blocksNum; ++i) {
                if (i == blocksNum - 1) {
                    calcSize = data.length - i * blockSize;
                }

                byte[] var22 = cp.doFinal(data, i * blockSize, calcSize);

                try {
                    outputStream.write(var22);
                } catch (IOException var19) {
                    throw new GeneralSecurityException("RSA error", var19);
                }
            }
            var21 = outputStream.toByteArray();
        } finally {
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException var18) {
                    ;
                }
            }

        }