小编Mag*_*eed的帖子

Java中的RSA加密

我试图在Java中使用RSA编写加密算法,我得到一个"javax.crypto.BadPaddingException:数据必须从零开始"; 我不知道这个例外是什么.这是我在这里使用的例子

这是我的代码; 请帮忙.

public byte[] getEncryptedValue(byte[] bytes, PublicKey key) {
    try {
        cipher.init(Cipher.ENCRYPT_MODE, key);
        return blockCipher(bytes, Cipher.ENCRYPT_MODE);
    } catch (Exception ex) {
        Logger.getLogger(SecurityUtil.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

public byte[] getDecryptedValue(byte[] bytes, PrivateKey key) {
    try {
        cipher.init(Cipher.DECRYPT_MODE, key);
        return blockCipher(bytes, Cipher.DECRYPT_MODE);
    } catch (Exception ex) {
        Logger.getLogger(SecurityUtil.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

private byte[] append(byte[] prefix, byte[] suffix) {
    byte[] toReturn = new byte[prefix.length + suffix.length];
    System.arraycopy(prefix, 0, toReturn, 0, prefix.length);
    System.arraycopy(suffix, 0, toReturn, …
Run Code Online (Sandbox Code Playgroud)

java security encryption rsa

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

标签 统计

encryption ×1

java ×1

rsa ×1

security ×1