public class RSA extends AsymmetricCrypto
RSA公钥/私钥/签名加密解密
罗纳德·李维斯特(Ron [R]ivest)、阿迪·萨莫尔(Adi [S]hamir)和伦纳德·阿德曼(Leonard [A]dleman)
由于非对称加密速度极其缓慢,一般文件不使用它来加密而是使用对称加密,
非对称加密算法可以用来对对称加密的密钥加密,这样保证密钥的安全也就保证了数据的安全
cipher, 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)
加密
|
String |
encryptStr(String data,
KeyType keyType)
Deprecated.
|
String |
encryptStr(String data,
KeyType keyType,
Charset charset)
Deprecated.
|
static PrivateKey |
generatePrivateKey(BigInteger modulus,
BigInteger privateExponent)
生成RSA私钥
|
static PublicKey |
generatePublicKey(BigInteger modulus,
BigInteger publicExponent)
生成RSA公钥
|
protected void |
initCipher()
初始化
Cipher ,默认尝试加载BC库 |
getAlgorithmParameterSpec, getCipher, getClipher, getDecryptBlockSize, getEncryptBlockSize, init, setAlgorithmParameterSpec, setDecryptBlockSize, setEncryptBlockSize
decrypt, decrypt, decryptFromBcd, decryptFromBcd, decryptStr, decryptStr, decryptStrFromBcd, decryptStrFromBcd, encrypt, encrypt, encrypt, encrypt, encryptBase64, encryptBase64, encryptBase64, encryptBase64, encryptBcd, encryptBcd, encryptHex, encryptHex, encryptHex, encryptHex
getKeyByType, getPrivateKey, getPrivateKeyBase64, getPublicKey, getPublicKeyBase64, initKeys, setKey, setPrivateKey, setPublicKey
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
@Deprecated public String encryptStr(String data, KeyType keyType)
AbstractAsymmetricCrypto.encryptBcd(String, KeyType)
data
- 数据keyType
- 密钥类型CryptoException
- 加密异常@Deprecated public String encryptStr(String data, KeyType keyType, Charset charset)
AbstractAsymmetricCrypto.encryptBcd(String, KeyType, Charset)
data
- 数据keyType
- 密钥类型charset
- 加密前编码CryptoException
- 加密异常public byte[] encrypt(byte[] data, KeyType keyType)
AsymmetricCrypto
encrypt
in class AsymmetricCrypto
data
- 被加密的byteskeyType
- 私钥或公钥 KeyType
public byte[] decrypt(byte[] bytes, KeyType keyType)
AsymmetricCrypto
decrypt
in class AsymmetricCrypto
bytes
- 被解密的byteskeyType
- 私钥或公钥 KeyType
protected void initCipher()
AsymmetricCrypto
Cipher
,默认尝试加载BC库initCipher
in class AsymmetricCrypto
Copyright © 2021. All rights reserved.