相关疑难解决方法(0)

bouncycastle支持RSA PKCS1-OAEP填充吗?

我正在Java/Android中实现加密代码以匹配iOS加密.在iOS中,使用以下填充方案使用RSA加密:PKCS1-OAEP

但是当我尝试用PKCS1-OAEP创建Cipher时.

Cipher c = Cipher.getInstance("RSA/None/PKCS1-OAEP", "BC");
Run Code Online (Sandbox Code Playgroud)

下面是堆栈跟踪

javax.crypto.NoSuchPaddingException: PKCS1-OAEP unavailable with RSA.
    at com.android.org.bouncycastle.jcajce.provider.asymmetric.rsa.CipherSpi.engineSetPadding(CipherSpi.java:240)
    at javax.crypto.Cipher.getCipher(Cipher.java:324)
    at javax.crypto.Cipher.getInstance(Cipher.java:237) 
Run Code Online (Sandbox Code Playgroud)

也许这RSA/None/PKCS1-OAEP是不正确的?但无法找到任何明确的答案,要么说PKCS1-OAEP不受支持,要么是正确的定义方式.

我正在使用spongycastle库,所以有完整的bouncycastle实现.

java security android bouncycastle

8
推荐指数
2
解决办法
1万
查看次数

java.lang.ArrayIndexOutOfBoundsException:RSA块的数据太多

我正在使用RSA加密文本和解密文本.使用openssl工具生成公钥和私钥.我在解密数据时遇到"java.lang.ArrayIndexOutOfBoundsException:RSA block的数据太多"异常.

这是RSA util类:

package studio.uphie.app;

import android.util.Base64;

import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;

import javax.crypto.Cipher;

/**
 * Created by Uphie on 2016/4/11.
 */
public class RSA {

    private static String RSA = "RSA";

    /**
     *
     * @param text    text to be encrypted
     * @param pub_key rsa public key
     * @return encrypted data in byte-array form
     */
    public static byte[] encryptData(String text, String pub_key) {
        try {
            byte[] data = text.getBytes();
            PublicKey …
Run Code Online (Sandbox Code Playgroud)

android rsa

1
推荐指数
1
解决办法
5107
查看次数

标签 统计

android ×2

bouncycastle ×1

java ×1

rsa ×1

security ×1