public class BCUtil extends Object
Constructor and Description |
---|
BCUtil() |
Modifier and Type | Method and Description |
---|---|
static PublicKey |
decodeECPoint(byte[] encodeByte,
String curveName)
解码恢复EC压缩公钥,支持Base64和Hex编码,(基于BouncyCastle)
|
static PublicKey |
decodeECPoint(String encode,
String curveName)
解码恢复EC压缩公钥,支持Base64和Hex编码,(基于BouncyCastle)
见:https://www.cnblogs.com/xinzhao/p/8963724.html |
static byte[] |
encodeECPrivateKey(PrivateKey privateKey)
只获取私钥里的d,32字节
|
static byte[] |
encodeECPublicKey(PublicKey publicKey)
编码压缩EC公钥(基于BouncyCastle),即Q值
见:https://www.cnblogs.com/xinzhao/p/8963724.html |
static byte[] |
encodeECPublicKey(PublicKey publicKey,
boolean isCompressed)
编码压缩EC公钥(基于BouncyCastle),即Q值
见:https://www.cnblogs.com/xinzhao/p/8963724.html |
static PrivateKey |
readPemPrivateKey(InputStream pemStream)
读取PEM格式的私钥
|
static PublicKey |
readPemPublicKey(InputStream pemStream)
读取PEM格式的公钥
|
static org.bouncycastle.crypto.params.ECDomainParameters |
toDomainParams(org.bouncycastle.jce.spec.ECParameterSpec parameterSpec)
构建ECDomainParameters对象
|
static org.bouncycastle.crypto.params.ECDomainParameters |
toDomainParams(String curveName)
构建ECDomainParameters对象
|
static org.bouncycastle.crypto.params.ECDomainParameters |
toDomainParams(org.bouncycastle.asn1.x9.X9ECParameters x9ECParameters)
构建ECDomainParameters对象
|
static org.bouncycastle.crypto.params.ECPublicKeyParameters |
toParams(BigInteger x,
BigInteger y,
org.bouncycastle.crypto.params.ECDomainParameters domainParameters)
转换为ECPublicKeyParameters
|
static org.bouncycastle.crypto.params.ECPrivateKeyParameters |
toParams(BigInteger d,
org.bouncycastle.crypto.params.ECDomainParameters domainParameters)
转换为 ECPrivateKeyParameters
|
static org.bouncycastle.crypto.params.ECPublicKeyParameters |
toParams(byte[] xBytes,
byte[] yBytes,
org.bouncycastle.crypto.params.ECDomainParameters domainParameters)
转换为ECPublicKeyParameters
|
static org.bouncycastle.crypto.params.ECPrivateKeyParameters |
toParams(byte[] d,
org.bouncycastle.crypto.params.ECDomainParameters domainParameters)
转换为 ECPrivateKeyParameters
|
static org.bouncycastle.crypto.params.AsymmetricKeyParameter |
toParams(Key key)
密钥转换为AsymmetricKeyParameter
|
static org.bouncycastle.crypto.params.ECPrivateKeyParameters |
toParams(PrivateKey privateKey)
私钥转换为
ECPrivateKeyParameters |
static org.bouncycastle.crypto.params.ECPublicKeyParameters |
toParams(PublicKey publicKey)
公钥转换为
ECPublicKeyParameters |
static org.bouncycastle.crypto.params.ECPrivateKeyParameters |
toParams(String dHex,
org.bouncycastle.crypto.params.ECDomainParameters domainParameters)
转换为 ECPrivateKeyParameters
|
static org.bouncycastle.crypto.params.ECPublicKeyParameters |
toParams(String xHex,
String yHex,
org.bouncycastle.crypto.params.ECDomainParameters domainParameters)
转换为ECPublicKeyParameters
|
static byte[] |
toPkcs1(PrivateKey privateKey)
Java中的PKCS#8格式私钥转换为OpenSSL支持的PKCS#1格式
|
static byte[] |
toPkcs1(PublicKey publicKey)
Java中的X.509格式公钥转换为OpenSSL支持的PKCS#1格式
|
static org.bouncycastle.crypto.params.ECPrivateKeyParameters |
toSm2Params(BigInteger d)
转换为 ECPrivateKeyParameters
|
static org.bouncycastle.crypto.params.ECPrivateKeyParameters |
toSm2Params(byte[] d)
转换为 ECPrivateKeyParameters
|
static org.bouncycastle.crypto.params.ECPublicKeyParameters |
toSm2Params(byte[] xBytes,
byte[] yBytes)
转换为SM2的ECPublicKeyParameters
|
static org.bouncycastle.crypto.params.ECPrivateKeyParameters |
toSm2Params(String d)
转换为 ECPrivateKeyParameters
|
static org.bouncycastle.crypto.params.ECPublicKeyParameters |
toSm2Params(String xHex,
String yHex)
转换为SM2的ECPublicKeyParameters
|
public static byte[] encodeECPrivateKey(PrivateKey privateKey)
privateKey
- PublicKey
,必须为org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKeypublic static byte[] encodeECPublicKey(PublicKey publicKey)
publicKey
- PublicKey
,必须为org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKeypublic static byte[] encodeECPublicKey(PublicKey publicKey, boolean isCompressed)
publicKey
- PublicKey
,必须为org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKeyisCompressed
- 是否压缩public static PublicKey decodeECPoint(String encode, String curveName)
encode
- 压缩公钥curveName
- EC曲线名public static PublicKey decodeECPoint(byte[] encodeByte, String curveName)
encodeByte
- 压缩公钥curveName
- EC曲线名,例如SmUtil.SM2_DOMAIN_PARAMS
public static org.bouncycastle.crypto.params.ECDomainParameters toDomainParams(org.bouncycastle.jce.spec.ECParameterSpec parameterSpec)
parameterSpec
- ECParameterSpecECDomainParameters
public static org.bouncycastle.crypto.params.ECDomainParameters toDomainParams(String curveName)
curveName
- Curve名称ECDomainParameters
public static org.bouncycastle.crypto.params.ECDomainParameters toDomainParams(org.bouncycastle.asn1.x9.X9ECParameters x9ECParameters)
x9ECParameters
- X9ECParameters
ECDomainParameters
public static org.bouncycastle.crypto.params.AsymmetricKeyParameter toParams(Key key)
key
- PrivateKey或者PublicKeypublic static org.bouncycastle.crypto.params.ECPrivateKeyParameters toSm2Params(String d)
d
- 私钥d值public static org.bouncycastle.crypto.params.ECPrivateKeyParameters toParams(String dHex, org.bouncycastle.crypto.params.ECDomainParameters domainParameters)
dHex
- 私钥d值16进制字符串domainParameters
- ECDomainParameterspublic static org.bouncycastle.crypto.params.ECPrivateKeyParameters toSm2Params(byte[] d)
d
- 私钥d值public static org.bouncycastle.crypto.params.ECPrivateKeyParameters toParams(byte[] d, org.bouncycastle.crypto.params.ECDomainParameters domainParameters)
d
- 私钥d值domainParameters
- ECDomainParameterspublic static org.bouncycastle.crypto.params.ECPrivateKeyParameters toSm2Params(BigInteger d)
d
- 私钥d值public static org.bouncycastle.crypto.params.ECPrivateKeyParameters toParams(BigInteger d, org.bouncycastle.crypto.params.ECDomainParameters domainParameters)
d
- 私钥d值domainParameters
- ECDomainParameterspublic static org.bouncycastle.crypto.params.ECPublicKeyParameters toParams(BigInteger x, BigInteger y, org.bouncycastle.crypto.params.ECDomainParameters domainParameters)
x
- 公钥Xy
- 公钥YdomainParameters
- ECDomainParameterspublic static org.bouncycastle.crypto.params.ECPublicKeyParameters toSm2Params(String xHex, String yHex)
xHex
- 公钥XyHex
- 公钥Ypublic static org.bouncycastle.crypto.params.ECPublicKeyParameters toParams(String xHex, String yHex, org.bouncycastle.crypto.params.ECDomainParameters domainParameters)
xHex
- 公钥XyHex
- 公钥YdomainParameters
- ECDomainParameterspublic static org.bouncycastle.crypto.params.ECPublicKeyParameters toSm2Params(byte[] xBytes, byte[] yBytes)
xBytes
- 公钥XyBytes
- 公钥Ypublic static org.bouncycastle.crypto.params.ECPublicKeyParameters toParams(byte[] xBytes, byte[] yBytes, org.bouncycastle.crypto.params.ECDomainParameters domainParameters)
xBytes
- 公钥XyBytes
- 公钥YdomainParameters
- ECDomainParameterspublic static org.bouncycastle.crypto.params.ECPublicKeyParameters toParams(PublicKey publicKey)
ECPublicKeyParameters
publicKey
- 公钥,传入null返回nullECPublicKeyParameters
或nullpublic static org.bouncycastle.crypto.params.ECPrivateKeyParameters toParams(PrivateKey privateKey)
ECPrivateKeyParameters
privateKey
- 私钥,传入null返回nullECPrivateKeyParameters
或nullpublic static PrivateKey readPemPrivateKey(InputStream pemStream)
pemStream
- pem流PrivateKey
PemUtil.readPemPrivateKey(InputStream)
public static PublicKey readPemPublicKey(InputStream pemStream)
pemStream
- pem流PublicKey
PemUtil.readPemPublicKey(InputStream)
public static byte[] toPkcs1(PrivateKey privateKey)
privateKey
- PKCS#8格式私钥public static byte[] toPkcs1(PublicKey publicKey)
publicKey
- X.509格式公钥Copyright © 2024. All rights reserved.