public class RSA extends AsymmetricCrypto
RSA公钥/私钥/签名加密解密
罗纳德·李维斯特(Ron [R]ivest)、阿迪·萨莫尔(Adi [S]hamir)和伦纳德·阿德曼(Leonard [A]dleman)
由于非对称加密速度极其缓慢,一般文件不使用它来加密而是使用对称加密,
非对称加密算法可以用来对对称加密的密钥加密,这样保证密钥的安全也就保证了数据的安全
cipher, decryptBlockSize, encryptBlockSizealgorithm, 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,
KeyPair keyPair)
构造
私钥和公钥同时为空时生成一对新的私钥和公钥 私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密 |
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, setRandomgetKeyByType, getPrivateKey, getPrivateKeyBase64, getPublicKey, getPublicKeyBase64, initKeys, setKey, setLock, setPrivateKey, setPublicKeyclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitencrypt, encrypt, encrypt, encryptBase64, encryptBase64, encryptBase64, encryptBase64, encryptHex, encryptHex, encryptHex, encryptHexdecrypt, decrypt, decryptStr, decryptStrpublic 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 static PrivateKey generatePrivateKey(BigInteger modulus, BigInteger privateExponent)
modulus - N特征值privateExponent - d特征值PrivateKeypublic static PublicKey generatePublicKey(BigInteger modulus, BigInteger publicExponent)
modulus - N特征值publicExponent - e特征值PublicKeypublic byte[] encrypt(byte[] data,
KeyType keyType)
AsymmetricEncryptorencrypt in interface AsymmetricEncryptorencrypt in class AsymmetricCryptodata - 被加密的byteskeyType - 私钥或公钥 KeyTypepublic byte[] decrypt(byte[] bytes,
KeyType keyType)
AsymmetricDecryptordecrypt in interface AsymmetricDecryptordecrypt in class AsymmetricCryptobytes - 被解密的byteskeyType - 私钥或公钥 KeyTypeprotected void initCipher()
AsymmetricCryptoCipher,默认尝试加载BC库initCipher in class AsymmetricCryptoCopyright © 2025. All rights reserved.