public class Asymmetric extends Safety<Asymmetric>
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 |
|---|
Asymmetric(String algorithm)
构造,创建新的私钥公钥对
|
Asymmetric(String algorithm,
byte[] privateKey,
byte[] publicKey)
构造
私钥和公钥同时为空时生成一对新的私钥和公钥
私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密
|
Asymmetric(String algorithm,
PrivateKey privateKey,
PublicKey publicKey)
构造
|
Asymmetric(String algorithm,
String privateKey,
String publicKey)
构造 私钥和公钥同时为空时生成一对新的私钥和公钥
私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
decrypt(byte[] data,
KeyType keyType)
解密
|
byte[] |
encrypt(byte[] data,
KeyType keyType)
加密
|
Cipher |
getClipher()
获得加密或解密器
|
int |
getDecryptBlockSize()
获取解密块大小
|
int |
getEncryptBlockSize()
获取加密块大小
|
Asymmetric |
init(String algorithm,
PrivateKey privateKey,
PublicKey publicKey)
私钥和公钥同时为空时生成一对新的私钥和公钥
私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密(签名)或者解密(校验)
|
protected void |
initCipher()
初始化
Cipher,默认尝试加载BC库 |
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, encryptHexgetKeyByType, getPrivateKey, getPrivateKeyBase64, getPublicKey, getPublicKeyBase64, initKeys, setKey, setPrivateKey, setPublicKeyprotected Cipher cipher
protected int encryptBlockSize
protected int decryptBlockSize
public Asymmetric(String algorithm)
algorithm - 算法public Asymmetric(String algorithm, String privateKey, String publicKey)
algorithm - 非对称加密算法privateKey - 私钥Base64publicKey - 公钥Base64public Asymmetric(String algorithm, byte[] privateKey, byte[] publicKey)
algorithm - 算法privateKey - 私钥publicKey - 公钥public Asymmetric(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 Asymmetric init(String algorithm, PrivateKey privateKey, PublicKey publicKey)
Keysinit in class Keys<Asymmetric>algorithm - 算法privateKey - 私钥publicKey - 公钥public byte[] encrypt(byte[] data,
KeyType keyType)
encrypt in class Safety<Asymmetric>data - 被加密的byteskeyType - 私钥或公钥 KeyTypepublic byte[] decrypt(byte[] data,
KeyType keyType)
decrypt in class Safety<Asymmetric>data - 被解密的byteskeyType - 私钥或公钥 KeyTypepublic Cipher getClipher()
protected void initCipher()
Cipher,默认尝试加载BC库Copyright © 2021. All rights reserved.