public class RSA extends AsymmetricCrypto
RSA公钥/私钥/签名加密解密
罗纳德·李维斯特(Ron [R]ivest)、阿迪·萨莫尔(Adi [S]hamir)和伦纳德·阿德曼(Leonard [A]dleman)
由于非对称加密速度极其缓慢,一般文件不使用它来加密而是使用对称加密,
非对称加密算法可以用来对对称加密的密钥加密,这样保证密钥的安全也就保证了数据的安全
cipher, decryptBlockSize, encryptBlockSizealgorithm, lock, privateKey, publicKey| 构造器和说明 |
|---|
RSA()
构造,生成新的私钥公钥对
|
RSA(java.math.BigInteger modulus,
java.math.BigInteger privateExponent,
java.math.BigInteger publicExponent)
构造
私钥和公钥同时为空时生成一对新的私钥和公钥 私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密 |
RSA(byte[] privateKey,
byte[] publicKey)
构造
私钥和公钥同时为空时生成一对新的私钥和公钥 私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密 |
RSA(java.security.PrivateKey privateKey,
java.security.PublicKey publicKey)
构造
私钥和公钥同时为空时生成一对新的私钥和公钥 私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密 |
RSA(java.lang.String rsaAlgorithm)
构造,生成新的私钥公钥对
|
RSA(java.lang.String rsaAlgorithm,
java.security.PrivateKey privateKey,
java.security.PublicKey publicKey)
构造
私钥和公钥同时为空时生成一对新的私钥和公钥 私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密 |
RSA(java.lang.String privateKeyStr,
java.lang.String publicKeyStr)
构造
私钥和公钥同时为空时生成一对新的私钥和公钥 私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密 |
RSA(java.lang.String rsaAlgorithm,
java.lang.String privateKeyStr,
java.lang.String publicKeyStr)
构造
私钥和公钥同时为空时生成一对新的私钥和公钥 私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密 |
| 限定符和类型 | 方法和说明 |
|---|---|
byte[] |
decrypt(byte[] bytes,
KeyType keyType)
解密
|
byte[] |
encrypt(byte[] data,
KeyType keyType)
加密
|
java.lang.String |
encryptStr(java.lang.String data,
KeyType keyType)
|
java.lang.String |
encryptStr(java.lang.String data,
KeyType keyType,
java.nio.charset.Charset charset)
|
static java.security.PrivateKey |
generatePrivateKey(java.math.BigInteger modulus,
java.math.BigInteger privateExponent)
生成RSA私钥
|
static java.security.PublicKey |
generatePublicKey(java.math.BigInteger modulus,
java.math.BigInteger publicExponent)
生成RSA公钥
|
protected void |
initCipher()
初始化
Cipher,默认尝试加载BC库 |
getClipher, getDecryptBlockSize, getEncryptBlockSize, init, setDecryptBlockSize, setEncryptBlockSizedecrypt, decrypt, decryptFromBcd, decryptFromBcd, decryptStr, decryptStr, decryptStrFromBcd, decryptStrFromBcd, encrypt, encrypt, encrypt, encrypt, encryptBase64, encryptBase64, encryptBase64, encryptBase64, encryptBcd, encryptBcd, encryptHex, encryptHex, encryptHex, encryptHexgetKeyByType, getPrivateKey, getPrivateKeyBase64, getPublicKey, getPublicKeyBase64, initKeys, setPrivateKey, setPublicKeypublic RSA()
public RSA(java.lang.String rsaAlgorithm)
rsaAlgorithm - 自定义RSA算法,例如RSA/ECB/PKCS1Paddingpublic RSA(java.lang.String privateKeyStr, java.lang.String publicKeyStr)
privateKeyStr - 私钥Hex或Base64表示publicKeyStr - 公钥Hex或Base64表示public RSA(java.lang.String rsaAlgorithm, java.lang.String privateKeyStr, java.lang.String publicKeyStr)
rsaAlgorithm - 自定义RSA算法,例如RSA/ECB/PKCS1PaddingprivateKeyStr - 私钥Hex或Base64表示publicKeyStr - 公钥Hex或Base64表示public RSA(byte[] privateKey, byte[] publicKey)
privateKey - 私钥publicKey - 公钥public RSA(java.math.BigInteger modulus, java.math.BigInteger privateExponent, java.math.BigInteger publicExponent)
modulus - N特征值privateExponent - d特征值publicExponent - e特征值public RSA(java.security.PrivateKey privateKey, java.security.PublicKey publicKey)
privateKey - 私钥publicKey - 公钥public RSA(java.lang.String rsaAlgorithm, java.security.PrivateKey privateKey, java.security.PublicKey publicKey)
rsaAlgorithm - 自定义RSA算法,例如RSA/ECB/PKCS1PaddingprivateKey - 私钥publicKey - 公钥public static java.security.PrivateKey generatePrivateKey(java.math.BigInteger modulus,
java.math.BigInteger privateExponent)
modulus - N特征值privateExponent - d特征值PrivateKeypublic static java.security.PublicKey generatePublicKey(java.math.BigInteger modulus,
java.math.BigInteger publicExponent)
modulus - N特征值publicExponent - e特征值PublicKey@Deprecated
public java.lang.String encryptStr(java.lang.String data,
KeyType keyType)
data - 数据keyType - 密钥类型CryptoException - 加密异常@Deprecated
public java.lang.String encryptStr(java.lang.String data,
KeyType keyType,
java.nio.charset.Charset charset)
data - 数据keyType - 密钥类型charset - 加密前编码CryptoException - 加密异常public byte[] encrypt(byte[] data,
KeyType keyType)
AsymmetricCryptoencrypt 在类中 AsymmetricCryptodata - 被加密的byteskeyType - 私钥或公钥 KeyTypepublic byte[] decrypt(byte[] bytes,
KeyType keyType)
AsymmetricCryptodecrypt 在类中 AsymmetricCryptobytes - 被解密的byteskeyType - 私钥或公钥 KeyTypeprotected void initCipher()
AsymmetricCryptoCipher,默认尝试加载BC库initCipher 在类中 AsymmetricCryptoCopyright © 2019. All rights reserved.