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,
PrivateKey privateKey,
PublicKey publicKey)
构造
|
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()
获得加密或解密器
|
Cipher |
getClipher()
Deprecated.
拼写错误,请使用
getCipher() |
int |
getDecryptBlockSize()
获取解密块大小
|
int |
getEncryptBlockSize()
获取加密块大小
|
AsymmetricCrypto |
init(String algorithm,
PrivateKey privateKey,
PublicKey publicKey)
初始化
私钥和公钥同时为空时生成一对新的私钥和公钥 私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密(签名)或者解密(校验) |
protected void |
initCipher()
初始化
Cipher ,默认尝试加载BC库 |
void |
setAlgorithmParameterSpec(AlgorithmParameterSpec algorithmParameterSpec)
设置
AlgorithmParameterSpec 在某些算法中,需要特别的参数,例如在ECIES中,此处为IESParameterSpec |
void |
setDecryptBlockSize(int decryptBlockSize)
设置解密块大小
|
void |
setEncryptBlockSize(int encryptBlockSize)
设置加密块大小
|
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
protected Cipher cipher
protected int encryptBlockSize
protected int decryptBlockSize
public AsymmetricCrypto(AsymmetricAlgorithm algorithm)
algorithm
- SymmetricAlgorithm
public AsymmetricCrypto(String algorithm)
algorithm
- 算法public AsymmetricCrypto(AsymmetricAlgorithm algorithm, String privateKeyStr, String publicKeyStr)
algorithm
- SymmetricAlgorithm
privateKeyStr
- 私钥Hex或Base64表示publicKeyStr
- 公钥Hex或Base64表示public AsymmetricCrypto(AsymmetricAlgorithm algorithm, byte[] privateKey, byte[] publicKey)
algorithm
- SymmetricAlgorithm
privateKey
- 私钥publicKey
- 公钥public AsymmetricCrypto(AsymmetricAlgorithm algorithm, PrivateKey privateKey, PublicKey publicKey)
algorithm
- SymmetricAlgorithm
privateKey
- 私钥publicKey
- 公钥public AsymmetricCrypto(String algorithm, String privateKeyBase64, String publicKeyBase64)
algorithm
- 非对称加密算法privateKeyBase64
- 私钥Base64publicKeyBase64
- 公钥Base64public AsymmetricCrypto(String algorithm, byte[] privateKey, byte[] publicKey)
私钥和公钥同时为空时生成一对新的私钥和公钥
私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密
algorithm
- 算法privateKey
- 私钥publicKey
- 公钥public AsymmetricCrypto(String algorithm, PrivateKey privateKey, PublicKey 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()
AlgorithmParameterSpec
AlgorithmParameterSpec
public void setAlgorithmParameterSpec(AlgorithmParameterSpec algorithmParameterSpec)
AlgorithmParameterSpec
algorithmParameterSpec
- AlgorithmParameterSpec
public AsymmetricCrypto init(String algorithm, PrivateKey privateKey, PublicKey publicKey)
BaseAsymmetric
init
in class BaseAsymmetric<AsymmetricCrypto>
algorithm
- 算法privateKey
- 私钥publicKey
- 公钥public byte[] encrypt(byte[] data, KeyType keyType)
encrypt
in class AbstractAsymmetricCrypto<AsymmetricCrypto>
data
- 被加密的byteskeyType
- 私钥或公钥 KeyType
public byte[] decrypt(byte[] data, KeyType keyType)
decrypt
in class AbstractAsymmetricCrypto<AsymmetricCrypto>
data
- 被解密的byteskeyType
- 私钥或公钥 KeyType
@Deprecated public Cipher getClipher()
getCipher()
public Cipher getCipher()
protected void initCipher()
Cipher
,默认尝试加载BC库Copyright © 2021. All rights reserved.