public class BaseAsymmetric<T extends BaseAsymmetric<T>> extends Object implements Serializable
Modifier and Type | Field and Description |
---|---|
protected String |
algorithm
算法
|
protected Lock |
lock
锁
|
protected PrivateKey |
privateKey
私钥
|
protected PublicKey |
publicKey
公钥
|
Constructor and Description |
---|
BaseAsymmetric(String algorithm,
PrivateKey privateKey,
PublicKey publicKey)
构造
私钥和公钥同时为空时生成一对新的私钥和公钥
私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密 |
Modifier and Type | Method and Description |
---|---|
protected Key |
getKeyByType(KeyType type)
根据密钥类型获得相应密钥
|
PrivateKey |
getPrivateKey()
获得私钥
|
String |
getPrivateKeyBase64()
获得私钥
|
PublicKey |
getPublicKey()
获得公钥
|
String |
getPublicKeyBase64()
获得公钥
|
protected T |
init(String algorithm,
PrivateKey privateKey,
PublicKey publicKey)
初始化
私钥和公钥同时为空时生成一对新的私钥和公钥 私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密(签名)或者解密(校验) |
T |
initKeys()
生成公钥和私钥
|
T |
setKey(Key key)
设置密钥,可以是公钥
PublicKey 或者私钥PrivateKey |
T |
setPrivateKey(PrivateKey privateKey)
设置私钥
|
T |
setPublicKey(PublicKey publicKey)
设置公钥
|
protected String algorithm
protected PublicKey publicKey
protected PrivateKey privateKey
protected final Lock lock
public BaseAsymmetric(String algorithm, PrivateKey privateKey, PublicKey publicKey)
私钥和公钥同时为空时生成一对新的私钥和公钥
私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做加密或者解密
algorithm
- 算法privateKey
- 私钥publicKey
- 公钥protected T init(String algorithm, PrivateKey privateKey, PublicKey publicKey)
algorithm
- 算法privateKey
- 私钥publicKey
- 公钥public T initKeys()
public PublicKey getPublicKey()
public String getPublicKeyBase64()
public T setPublicKey(PublicKey publicKey)
publicKey
- 公钥public PrivateKey getPrivateKey()
public String getPrivateKeyBase64()
public T setPrivateKey(PrivateKey privateKey)
privateKey
- 私钥public T setKey(Key key)
PublicKey
或者私钥PrivateKey
key
- 密钥,可以是公钥PublicKey
或者私钥PrivateKey
Copyright © 2024. All rights reserved.