public class KeyUtil
extends java.lang.Object
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
DEFAULT_KEY_SIZE
默认密钥字节数
RSA/DSA
Default Keysize 1024
Keysize must be a multiple of 64, ranging from 512 to 1024 (inclusive).
|
static java.lang.String |
KEY_STORE
Java密钥库(Java Key Store,JKS)KEY_STORE
|
static java.lang.String |
SM2_DEFAULT_CURVE
SM2默认曲线
Default SM2 curve
|
static java.lang.String |
X509 |
| 构造器和说明 |
|---|
KeyUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static java.security.PublicKey |
decodeECPoint(byte[] encodeByte,
java.lang.String curveName)
解码恢复EC压缩公钥,支持Base64和Hex编码,(基于BouncyCastle)
见:https://www.cnblogs.com/xinzhao/p/8963724.html |
static java.security.PublicKey |
decodeECPoint(java.lang.String encode,
java.lang.String curveName)
解码恢复EC压缩公钥,支持Base64和Hex编码,(基于BouncyCastle)
见:https://www.cnblogs.com/xinzhao/p/8963724.html |
static byte[] |
encodeECPublicKey(java.security.PublicKey publicKey)
编码压缩EC公钥(基于BouncyCastle)
见:https://www.cnblogs.com/xinzhao/p/8963724.html |
static javax.crypto.SecretKey |
generateDESKey(java.lang.String algorithm,
byte[] key)
生成
SecretKey |
static javax.crypto.SecretKey |
generateKey(java.lang.String algorithm)
生成
SecretKey,仅用于对称加密和摘要算法密钥生成 |
static javax.crypto.SecretKey |
generateKey(java.lang.String algorithm,
byte[] key)
生成
SecretKey,仅用于对称加密和摘要算法密钥生成 |
static javax.crypto.SecretKey |
generateKey(java.lang.String algorithm,
int keySize)
生成
SecretKey,仅用于对称加密和摘要算法密钥生成 |
static javax.crypto.SecretKey |
generateKey(java.lang.String algorithm,
java.security.spec.KeySpec keySpec)
生成
SecretKey,仅用于对称加密和摘要算法 |
static java.security.KeyPair |
generateKeyPair(java.lang.String algorithm)
生成用于非对称加密的公钥和私钥,仅用于非对称加密
密钥对生成算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator |
static java.security.KeyPair |
generateKeyPair(java.lang.String algorithm,
java.security.spec.AlgorithmParameterSpec params)
生成用于非对称加密的公钥和私钥
密钥对生成算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator |
static java.security.KeyPair |
generateKeyPair(java.lang.String algorithm,
byte[] seed,
java.security.spec.AlgorithmParameterSpec param)
生成用于非对称加密的公钥和私钥
密钥对生成算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator |
static java.security.KeyPair |
generateKeyPair(java.lang.String algorithm,
int keySize)
生成用于非对称加密的公钥和私钥
密钥对生成算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator |
static java.security.KeyPair |
generateKeyPair(java.lang.String algorithm,
int keySize,
byte[] seed)
生成用于非对称加密的公钥和私钥
密钥对生成算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator |
static java.security.KeyPair |
generateKeyPair(java.lang.String algorithm,
int keySize,
byte[] seed,
java.security.spec.AlgorithmParameterSpec... params)
生成用于非对称加密的公钥和私钥
密钥对生成算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator |
static javax.crypto.SecretKey |
generatePBEKey(java.lang.String algorithm,
char[] key)
生成PBE
SecretKey |
static java.security.PrivateKey |
generatePrivateKey(java.security.KeyStore keyStore,
java.lang.String alias,
char[] password)
生成私钥,仅用于非对称加密
|
static java.security.PrivateKey |
generatePrivateKey(java.lang.String algorithm,
byte[] key)
生成私钥,仅用于非对称加密
采用PKCS#8规范,此规范定义了私钥信息语法和加密私钥语法 算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyFactory |
static java.security.PrivateKey |
generatePrivateKey(java.lang.String algorithm,
java.security.spec.KeySpec keySpec)
生成私钥,仅用于非对称加密
算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyFactory |
static java.security.PublicKey |
generatePublicKey(java.lang.String algorithm,
byte[] key)
生成公钥,仅用于非对称加密
采用X509证书规范 算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyFactory |
static java.security.PublicKey |
generatePublicKey(java.lang.String algorithm,
java.security.spec.KeySpec keySpec)
生成公钥,仅用于非对称加密
算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyFactory |
static java.security.PrivateKey |
generateRSAPrivateKey(byte[] key)
生成RSA私钥,仅用于非对称加密
采用PKCS#8规范,此规范定义了私钥信息语法和加密私钥语法 算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyFactory |
static java.security.PublicKey |
generateRSAPublicKey(byte[] key)
生成RSA公钥,仅用于非对称加密
采用X509证书规范 算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyFactory |
static java.lang.String |
getAlgorithmAfterWith(java.lang.String algorithm)
获取用于密钥生成的算法
获取XXXwithXXX算法的后半部分算法,如果为ECDSA或SM2,返回算法为EC |
static java.security.cert.Certificate |
getCertificate(java.security.KeyStore keyStore,
java.lang.String alias)
获得 Certification
|
static java.security.cert.CertificateFactory |
getCertificateFactory(java.lang.String type)
获取
CertificateFactory |
static java.security.KeyFactory |
getKeyFactory(java.lang.String algorithm)
获取
KeyFactory |
static javax.crypto.KeyGenerator |
getKeyGenerator(java.lang.String algorithm)
获取
KeyGenerator |
static java.security.KeyPair |
getKeyPair(java.security.KeyStore keyStore,
char[] password,
java.lang.String alias)
从KeyStore中获取私钥公钥
|
static java.security.KeyPair |
getKeyPair(java.lang.String type,
java.io.InputStream in,
char[] password,
java.lang.String alias)
从KeyStore中获取私钥公钥
|
static java.security.KeyPairGenerator |
getKeyPairGenerator(java.lang.String algorithm)
获取
KeyPairGenerator |
static java.lang.String |
getMainAlgorithm(java.lang.String algorithm)
获取主体算法名,例如RSA/ECB/PKCS1Padding的主体算法是RSA
|
static javax.crypto.SecretKeyFactory |
getSecretKeyFactory(java.lang.String algorithm)
获取
SecretKeyFactory |
static java.security.cert.Certificate |
readCertificate(java.lang.String type,
java.io.InputStream in)
读取Certification文件
Certification为证书文件 see: http://snowolf.iteye.com/blog/391931 |
static java.security.cert.Certificate |
readCertificate(java.lang.String type,
java.io.InputStream in,
char[] password,
java.lang.String alias)
读取Certification文件
Certification为证书文件 see: http://snowolf.iteye.com/blog/391931 |
static java.security.KeyStore |
readJKSKeyStore(java.io.InputStream in,
char[] password)
读取密钥库(Java Key Store,JKS) KeyStore文件
KeyStore文件用于数字证书的密钥对保存 see: http://snowolf.iteye.com/blog/391931 |
static java.security.KeyStore |
readKeyStore(java.lang.String type,
java.io.InputStream in,
char[] password)
读取KeyStore文件
KeyStore文件用于数字证书的密钥对保存 see: http://snowolf.iteye.com/blog/391931 |
static java.security.PublicKey |
readPublicKeyFromCert(java.io.InputStream in)
读取X.509 Certification文件中的公钥
Certification为证书文件 see: https://www.cnblogs.com/yinliang/p/10115519.html |
static java.security.cert.Certificate |
readX509Certificate(java.io.InputStream in)
读取X.509 Certification文件
Certification为证书文件 see: http://snowolf.iteye.com/blog/391931 |
static java.security.cert.Certificate |
readX509Certificate(java.io.InputStream in,
char[] password,
java.lang.String alias)
读取X.509 Certification文件
Certification为证书文件 see: http://snowolf.iteye.com/blog/391931 |
public static final java.lang.String KEY_STORE
public static final java.lang.String X509
public static final int DEFAULT_KEY_SIZE
RSA/DSA Default Keysize 1024 Keysize must be a multiple of 64, ranging from 512 to 1024 (inclusive).
public static final java.lang.String SM2_DEFAULT_CURVE
Default SM2 curve
public static javax.crypto.SecretKey generateKey(java.lang.String algorithm)
SecretKey,仅用于对称加密和摘要算法密钥生成algorithm - 算法,支持PBE算法SecretKeypublic static javax.crypto.SecretKey generateKey(java.lang.String algorithm,
int keySize)
SecretKey,仅用于对称加密和摘要算法密钥生成algorithm - 算法,支持PBE算法keySize - 密钥长度SecretKeypublic static javax.crypto.SecretKey generateKey(java.lang.String algorithm,
byte[] key)
SecretKey,仅用于对称加密和摘要算法密钥生成algorithm - 算法key - 密钥,如果为null 自动生成随机密钥SecretKeypublic static javax.crypto.SecretKey generateDESKey(java.lang.String algorithm,
byte[] key)
SecretKeyalgorithm - DES算法,包括DES、DESede等key - 密钥SecretKeypublic static javax.crypto.SecretKey generatePBEKey(java.lang.String algorithm,
char[] key)
SecretKeyalgorithm - PBE算法,包括:PBEWithMD5AndDES、PBEWithSHA1AndDESede、PBEWithSHA1AndRC2_40等key - 密钥SecretKeypublic static javax.crypto.SecretKey generateKey(java.lang.String algorithm,
java.security.spec.KeySpec keySpec)
SecretKey,仅用于对称加密和摘要算法algorithm - 算法keySpec - KeySpecSecretKeypublic static java.security.PrivateKey generateRSAPrivateKey(byte[] key)
key - 密钥,必须为DER编码存储PrivateKeypublic static java.security.PrivateKey generatePrivateKey(java.lang.String algorithm,
byte[] key)
algorithm - 算法key - 密钥,必须为DER编码存储PrivateKeypublic static java.security.PrivateKey generatePrivateKey(java.lang.String algorithm,
java.security.spec.KeySpec keySpec)
algorithm - 算法keySpec - KeySpecPrivateKeypublic static java.security.PrivateKey generatePrivateKey(java.security.KeyStore keyStore,
java.lang.String alias,
char[] password)
keyStore - KeyStorealias - 别名password - 密码PrivateKeypublic static java.security.PublicKey generateRSAPublicKey(byte[] key)
key - 密钥,必须为DER编码存储PublicKeypublic static java.security.PublicKey generatePublicKey(java.lang.String algorithm,
byte[] key)
algorithm - 算法key - 密钥,必须为DER编码存储PublicKeypublic static java.security.PublicKey generatePublicKey(java.lang.String algorithm,
java.security.spec.KeySpec keySpec)
algorithm - 算法keySpec - KeySpecPublicKeypublic static java.security.KeyPair generateKeyPair(java.lang.String algorithm)
algorithm - 非对称加密算法KeyPairpublic static java.security.KeyPair generateKeyPair(java.lang.String algorithm,
int keySize)
algorithm - 非对称加密算法keySize - 密钥模(modulus )长度KeyPairpublic static java.security.KeyPair generateKeyPair(java.lang.String algorithm,
int keySize,
byte[] seed)
algorithm - 非对称加密算法keySize - 密钥模(modulus )长度seed - 种子KeyPairpublic static java.security.KeyPair generateKeyPair(java.lang.String algorithm,
java.security.spec.AlgorithmParameterSpec params)
algorithm - 非对称加密算法params - AlgorithmParameterSpecKeyPairpublic static java.security.KeyPair generateKeyPair(java.lang.String algorithm,
byte[] seed,
java.security.spec.AlgorithmParameterSpec param)
algorithm - 非对称加密算法param - AlgorithmParameterSpecseed - 种子KeyPairpublic static java.security.KeyPair generateKeyPair(java.lang.String algorithm,
int keySize,
byte[] seed,
java.security.spec.AlgorithmParameterSpec... params)
algorithm - 非对称加密算法keySize - 密钥模(modulus )长度seed - 种子params - AlgorithmParameterSpecKeyPairpublic static java.security.KeyPairGenerator getKeyPairGenerator(java.lang.String algorithm)
KeyPairGeneratoralgorithm - 非对称加密算法KeyPairGeneratorpublic static java.security.KeyFactory getKeyFactory(java.lang.String algorithm)
KeyFactoryalgorithm - 非对称加密算法KeyFactorypublic static javax.crypto.SecretKeyFactory getSecretKeyFactory(java.lang.String algorithm)
SecretKeyFactoryalgorithm - 对称加密算法KeyFactorypublic static javax.crypto.KeyGenerator getKeyGenerator(java.lang.String algorithm)
KeyGeneratoralgorithm - 对称加密算法KeyGeneratorpublic static java.lang.String getMainAlgorithm(java.lang.String algorithm)
public static java.lang.String getAlgorithmAfterWith(java.lang.String algorithm)
algorithm - XXXwithXXX算法public static java.security.KeyStore readJKSKeyStore(java.io.InputStream in,
char[] password)
in - InputStream 如果想从文件读取.keystore文件,使用 FileUtil.getInputStream(java.io.File) 读取password - 密码KeyStorepublic static java.security.KeyStore readKeyStore(java.lang.String type,
java.io.InputStream in,
char[] password)
type - 类型in - InputStream 如果想从文件读取.keystore文件,使用 FileUtil.getInputStream(java.io.File) 读取password - 密码KeyStorepublic static java.security.KeyPair getKeyPair(java.lang.String type,
java.io.InputStream in,
char[] password,
java.lang.String alias)
type - 类型in - InputStream 如果想从文件读取.keystore文件,使用 FileUtil.getInputStream(java.io.File) 读取password - 密码alias - 别名KeyPairpublic static java.security.KeyPair getKeyPair(java.security.KeyStore keyStore,
char[] password,
java.lang.String alias)
keyStore - KeyStorepassword - 密码alias - 别名KeyPairpublic static java.security.cert.Certificate readX509Certificate(java.io.InputStream in,
char[] password,
java.lang.String alias)
in - InputStream 如果想从文件读取.cer文件,使用 FileUtil.getInputStream(java.io.File) 读取password - 密码alias - 别名KeyStorepublic static java.security.PublicKey readPublicKeyFromCert(java.io.InputStream in)
in - InputStream 如果想从文件读取.cer文件,使用 FileUtil.getInputStream(java.io.File) 读取KeyStorepublic static java.security.cert.Certificate readX509Certificate(java.io.InputStream in)
in - InputStream 如果想从文件读取.cer文件,使用 FileUtil.getInputStream(java.io.File) 读取KeyStorepublic static java.security.cert.Certificate readCertificate(java.lang.String type,
java.io.InputStream in,
char[] password,
java.lang.String alias)
type - 类型,例如X.509in - InputStream 如果想从文件读取.cer文件,使用 FileUtil.getInputStream(java.io.File) 读取password - 密码alias - 别名KeyStorepublic static java.security.cert.Certificate readCertificate(java.lang.String type,
java.io.InputStream in)
type - 类型,例如X.509in - InputStream 如果想从文件读取.cer文件,使用 FileUtil.getInputStream(java.io.File) 读取Certificatepublic static java.security.cert.Certificate getCertificate(java.security.KeyStore keyStore,
java.lang.String alias)
keyStore - KeyStorealias - 别名Certificatepublic static java.security.cert.CertificateFactory getCertificateFactory(java.lang.String type)
CertificateFactorytype - 类型,例如X.509KeyPairGeneratorpublic static byte[] encodeECPublicKey(java.security.PublicKey publicKey)
publicKey - PublicKey,必须为org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKeypublic static java.security.PublicKey decodeECPoint(java.lang.String encode,
java.lang.String curveName)
encode - 压缩公钥curveName - EC曲线名public static java.security.PublicKey decodeECPoint(byte[] encodeByte,
java.lang.String curveName)
encodeByte - 压缩公钥curveName - EC曲线名Copyright © 2019. All rights reserved.