public class RSA extends AsymmetricCrypto
RSA公钥/私钥/签名加密解密
罗纳德·李维斯特(Ron [R]ivest)、阿迪·萨莫尔(Adi [S]hamir)和伦纳德·阿德曼(Leonard [A]dleman)
由于非对称加密速度极其缓慢,一般文件不使用它来加密而是使用对称加密,
非对称加密算法可以用来对对称加密的密钥加密,这样保证密钥的安全也就保证了数据的安全
cipherWrapper, decryptBlockSize, encryptBlockSize
algorithm, lock, privateKey, publicKey
Constructor and Description |
---|
RSA()
构造,生成新的私钥公钥对
|
RSA(BigInteger modulus,
BigInteger privateExponent,
BigInteger publicExponent)
构造
私钥和公钥同时为空时生成一对新的私钥和公钥 私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密 |
RSA(byte[] privateKey,
byte[] publicKey)
构造
私钥和公钥同时为空时生成一对新的私钥和公钥 私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密 |
RSA(PrivateKey privateKey,
PublicKey publicKey)
构造
私钥和公钥同时为空时生成一对新的私钥和公钥 私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密 |
RSA(String rsaAlgorithm)
构造,生成新的私钥公钥对
|
RSA(String rsaAlgorithm,
PrivateKey privateKey,
PublicKey publicKey)
构造
私钥和公钥同时为空时生成一对新的私钥和公钥 私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密 |
RSA(String privateKeyStr,
String publicKeyStr)
构造
私钥和公钥同时为空时生成一对新的私钥和公钥 私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密 |
RSA(String rsaAlgorithm,
String privateKeyStr,
String publicKeyStr)
构造
私钥和公钥同时为空时生成一对新的私钥和公钥 私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密 |
Modifier and Type | Method and Description |
---|---|
byte[] |
decrypt(byte[] bytes,
KeyType keyType)
解密
|
byte[] |
encrypt(byte[] data,
KeyType keyType)
加密
|
static PrivateKey |
generatePrivateKey(BigInteger modulus,
BigInteger privateExponent)
生成RSA私钥
|
static PublicKey |
generatePublicKey(BigInteger modulus,
BigInteger publicExponent)
生成RSA公钥
|
protected void |
initCipher()
初始化
Cipher ,默认尝试加载BC库 |
getAlgorithmParameterSpec, getCipher, getDecryptBlockSize, getEncryptBlockSize, init, setAlgorithmParameterSpec, setDecryptBlockSize, setEncryptBlockSize, setRandom
getKeyByType, getPrivateKey, getPrivateKeyBase64, getPublicKey, getPublicKeyBase64, initKeys, setKey, setPrivateKey, setPublicKey
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
encrypt, encrypt, encrypt, encrypt, encryptBase64, encryptBase64, encryptBase64, encryptBase64, encryptBcd, encryptBcd, encryptHex, encryptHex, encryptHex, encryptHex
decrypt, decrypt, decryptFromBcd, decryptFromBcd, decryptStr, decryptStr, decryptStrFromBcd, decryptStrFromBcd
public RSA()
public RSA(String rsaAlgorithm)
rsaAlgorithm
- 自定义RSA算法,例如RSA/ECB/PKCS1Paddingpublic RSA(String privateKeyStr, String publicKeyStr)
privateKeyStr
- 私钥Hex或Base64表示publicKeyStr
- 公钥Hex或Base64表示public RSA(String rsaAlgorithm, String privateKeyStr, String publicKeyStr)
rsaAlgorithm
- 自定义RSA算法,例如RSA/ECB/PKCS1PaddingprivateKeyStr
- 私钥Hex或Base64表示publicKeyStr
- 公钥Hex或Base64表示public RSA(byte[] privateKey, byte[] publicKey)
privateKey
- 私钥publicKey
- 公钥public RSA(BigInteger modulus, BigInteger privateExponent, BigInteger publicExponent)
modulus
- N特征值privateExponent
- d特征值publicExponent
- e特征值public RSA(PrivateKey privateKey, PublicKey publicKey)
privateKey
- 私钥publicKey
- 公钥public RSA(String rsaAlgorithm, PrivateKey privateKey, PublicKey publicKey)
rsaAlgorithm
- 自定义RSA算法,例如RSA/ECB/PKCS1PaddingprivateKey
- 私钥publicKey
- 公钥public static PrivateKey generatePrivateKey(BigInteger modulus, BigInteger privateExponent)
modulus
- N特征值privateExponent
- d特征值PrivateKey
public static PublicKey generatePublicKey(BigInteger modulus, BigInteger publicExponent)
modulus
- N特征值publicExponent
- e特征值PublicKey
public byte[] encrypt(byte[] data, KeyType keyType)
AsymmetricEncryptor
encrypt
in interface AsymmetricEncryptor
encrypt
in class AsymmetricCrypto
data
- 被加密的byteskeyType
- 私钥或公钥 KeyType
public byte[] decrypt(byte[] bytes, KeyType keyType)
AsymmetricDecryptor
decrypt
in interface AsymmetricDecryptor
decrypt
in class AsymmetricCrypto
bytes
- 被解密的byteskeyType
- 私钥或公钥 KeyType
protected void initCipher()
AsymmetricCrypto
Cipher
,默认尝试加载BC库initCipher
in class AsymmetricCrypto
Copyright © 2024. All rights reserved.