public class AsymmetricCrypto extends AbstractAsymmetricCrypto<AsymmetricCrypto>
1、签名:使用私钥加密,公钥解密。 用于让所有公钥所有者验证私钥所有者的身份并且用来防止私钥所有者发布的内容被篡改,但是不用来保证内容不被他人获得。 2、加密:用公钥加密,私钥解密。 用于向公钥所有者发布信息,这个信息可能被他人篡改,但是无法被他人获得。
| Modifier and Type | Field and Description |
|---|---|
protected Cipher |
cipher
Cipher负责完成加密或解密工作
|
protected int |
decryptBlockSize
解密的块大小
|
protected int |
encryptBlockSize
加密的块大小
|
algorithm, lock, privateKey, publicKey| Constructor and Description |
|---|
AsymmetricCrypto(AsymmetricAlgorithm algorithm)
构造,创建新的私钥公钥对
|
AsymmetricCrypto(AsymmetricAlgorithm algorithm,
byte[] privateKey,
byte[] publicKey)
构造 私钥和公钥同时为空时生成一对新的私钥和公钥
私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密 |
AsymmetricCrypto(AsymmetricAlgorithm algorithm,
PrivateKey privateKey,
PublicKey publicKey)
构造 私钥和公钥同时为空时生成一对新的私钥和公钥
私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密 |
AsymmetricCrypto(AsymmetricAlgorithm algorithm,
String privateKeyStr,
String publicKeyStr)
构造 私钥和公钥同时为空时生成一对新的私钥和公钥
私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密 |
AsymmetricCrypto(String algorithm)
构造,创建新的私钥公钥对
|
AsymmetricCrypto(String algorithm,
byte[] privateKey,
byte[] publicKey)
构造
私钥和公钥同时为空时生成一对新的私钥和公钥
私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密 |
AsymmetricCrypto(String algorithm,
KeyPair keyPair)
构造
私钥和公钥同时为空时生成一对新的私钥和公钥
私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密 |
AsymmetricCrypto(String algorithm,
String privateKeyBase64,
String publicKeyBase64)
构造 私钥和公钥同时为空时生成一对新的私钥和公钥
私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密 |
| Modifier and Type | Method and Description |
|---|---|
byte[] |
decrypt(byte[] data,
KeyType keyType)
解密
|
byte[] |
encrypt(byte[] data,
KeyType keyType)
加密
|
AlgorithmParameterSpec |
getAlgorithmParameterSpec()
获取
AlgorithmParameterSpec在某些算法中,需要特别的参数,例如在ECIES中,此处为IESParameterSpec |
Cipher |
getCipher()
获得加密或解密器
|
int |
getDecryptBlockSize()
获取解密块大小
|
int |
getEncryptBlockSize()
获取加密块大小
|
AsymmetricCrypto |
init(String algorithm,
KeyPair keyPair)
初始化
私钥和公钥同时为空时生成一对新的私钥和公钥 私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密(签名)或者解密(校验) |
protected void |
initCipher()
初始化
Cipher,默认尝试加载BC库 |
AsymmetricCrypto |
setAlgorithmParameterSpec(AlgorithmParameterSpec algorithmParameterSpec)
设置
AlgorithmParameterSpec在某些算法中,需要特别的参数,例如在ECIES中,此处为IESParameterSpec |
void |
setDecryptBlockSize(int decryptBlockSize)
设置解密块大小
|
void |
setEncryptBlockSize(int encryptBlockSize)
设置加密块大小
|
AsymmetricCrypto |
setRandom(SecureRandom random)
设置随机数生成器,可自定义随机数种子
|
getKeyByType, 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, decryptStrprotected Cipher cipher
protected int encryptBlockSize
protected int decryptBlockSize
public AsymmetricCrypto(AsymmetricAlgorithm algorithm)
algorithm - SymmetricAlgorithmpublic AsymmetricCrypto(String algorithm)
algorithm - 算法public AsymmetricCrypto(AsymmetricAlgorithm algorithm, String privateKeyStr, String publicKeyStr)
algorithm - SymmetricAlgorithmprivateKeyStr - 私钥Hex或Base64表示publicKeyStr - 公钥Hex或Base64表示public AsymmetricCrypto(AsymmetricAlgorithm algorithm, byte[] privateKey, byte[] publicKey)
algorithm - SymmetricAlgorithmprivateKey - 私钥publicKey - 公钥public AsymmetricCrypto(AsymmetricAlgorithm algorithm, PrivateKey privateKey, PublicKey publicKey)
algorithm - SymmetricAlgorithmprivateKey - 私钥publicKey - 公钥public AsymmetricCrypto(String algorithm, String privateKeyBase64, String publicKeyBase64)
algorithm - 非对称加密算法privateKeyBase64 - 私钥Base64publicKeyBase64 - 公钥Base64public AsymmetricCrypto(String algorithm, byte[] privateKey, byte[] publicKey)
私钥和公钥同时为空时生成一对新的私钥和公钥
私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密
algorithm - 算法privateKey - 私钥publicKey - 公钥public int getEncryptBlockSize()
public void setEncryptBlockSize(int encryptBlockSize)
encryptBlockSize - 加密块大小public int getDecryptBlockSize()
public void setDecryptBlockSize(int decryptBlockSize)
decryptBlockSize - 解密块大小public AlgorithmParameterSpec getAlgorithmParameterSpec()
AlgorithmParameterSpecAlgorithmParameterSpecpublic AsymmetricCrypto setAlgorithmParameterSpec(AlgorithmParameterSpec algorithmParameterSpec)
AlgorithmParameterSpecalgorithmParameterSpec - AlgorithmParameterSpecpublic AsymmetricCrypto setRandom(SecureRandom random)
random - 随机数生成器,可自定义随机数种子public AsymmetricCrypto init(String algorithm, KeyPair keyPair)
BaseAsymmetricinit in class BaseAsymmetric<AsymmetricCrypto>algorithm - 算法keyPair - 密钥对,包括私钥和公钥public byte[] encrypt(byte[] data,
KeyType keyType)
AsymmetricEncryptordata - 被加密的byteskeyType - 私钥或公钥 KeyTypepublic byte[] decrypt(byte[] data,
KeyType keyType)
AsymmetricDecryptordata - 被解密的byteskeyType - 私钥或公钥 KeyTypepublic Cipher getCipher()
protected void initCipher()
Cipher,默认尝试加载BC库Copyright © 2025. All rights reserved.