public class SecurityUtils extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
DEFAULT_KEY_SIZE
默认密钥字节数
RSA/DSA
Default Keysize 1024
Keysize must be a multiple of 64, ranging from 512 to 1024 (inclusive).
|
| 构造器和说明 |
|---|
SecurityUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static SymmetricCriptor |
aes()
AES加密,生成随机KEY。
|
static SymmetricCriptor |
aes(byte[] key)
AES加密
例: AES加密:aes(key).encrypt(data) AES解密:aes(key).decrypt(data) |
static SymmetricCriptor |
des()
DES加密,生成随机KEY。
|
static SymmetricCriptor |
des(byte[] key)
DES加密
例: DES加密:des(key).encrypt(data) DES解密:des(key).decrypt(data) |
static SecretKey |
generateDESKey(String algorithm,
byte[] key)
生成
SecretKey |
static SecretKey |
generateKey(String algorithm)
生成
SecretKey |
static SecretKey |
generateKey(String algorithm,
byte[] key)
生成
SecretKey |
static SecretKey |
generateKey(String algorithm,
KeySpec keySpec)
生成
SecretKey |
static KeyPair |
generateKeyPair(String algorithm)
生成用于非对称加密的公钥和私钥
|
static KeyPair |
generateKeyPair(String algorithm,
int keySize)
生成用于非对称加密的公钥和私钥
|
static KeyPair |
generateKeyPair(String algorithm,
int keySize,
byte[] seed)
生成用于非对称加密的公钥和私钥
|
static SecretKey |
generatePBEKey(String algorithm,
char[] key)
生成PBE
SecretKey |
static PrivateKey |
generatePrivateKey(KeyStore keyStore,
String alias,
char[] password)
生成私钥
|
static PrivateKey |
generatePrivateKey(String algorithm,
byte[] key)
生成私钥
|
static PublicKey |
generatePublicKey(String algorithm,
byte[] key)
生成公钥
|
static Signature |
generateSignature(AsymmetricAlgorithm asymmetricAlgorithm,
DigestAlgorithm digestAlgorithm)
生成签名对象
|
static Certificate |
getCertificate(KeyStore keyStore,
String alias)
获得 Certification
|
static HMac |
hmacMd5()
HmacMD5加密器,生成随机KEY
例: HmacMD5加密:hmacMd5().digest(data) HmacMD5加密并转为16进制字符串:hmacMd5().digestHex(data) |
static HMac |
hmacMd5(byte[] key)
HmacMD5加密器
例: HmacMD5加密:hmacMd5(key).digest(data) HmacMD5加密并转为16进制字符串:hmacMd5(key).digestHex(data) |
static HMac |
hmacSha1()
HmacSHA1加密器,生成随机KEY
例: HmacSHA1加密:hmacSha1().digest(data) HmacSHA1加密并转为16进制字符串:hmacSha1().digestHex(data) |
static HMac |
hmacSha1(byte[] key)
HmacSHA1加密器
例: HmacSHA1加密:hmacSha1(key).digest(data) HmacSHA1加密并转为16进制字符串:hmacSha1(key).digestHex(data) |
static Digester |
md5()
MD5加密
例: MD5加密:md5().digest(data) MD5加密并转为16进制字符串:md5().digestHex(data) |
static String |
md5(File dataFile)
MD5加密文件,生成16进制MD5字符串
|
static String |
md5(InputStream data)
MD5加密,生成16进制MD5字符串
|
static String |
md5(String data)
MD5加密,生成16进制MD5字符串
|
static Certificate |
readCertificate(String type,
InputStream in,
char[] password)
读取Certification文件
Certification为证书文件 see: http://snowolf.iteye.com/blog/391931 |
static KeyStore |
readJKSKeyStore(InputStream in,
char[] password)
读取密钥库(Java Key Store,JKS) KeyStore文件
KeyStore文件用于数字证书的密钥对保存 see: http://snowolf.iteye.com/blog/391931 |
static KeyStore |
readKeyStore(String type,
InputStream in,
char[] password)
读取KeyStore文件
KeyStore文件用于数字证书的密钥对保存 see: http://snowolf.iteye.com/blog/391931 |
static Certificate |
readX509Certificate(InputStream in,
char[] password)
读取X.509 Certification文件
Certification为证书文件 see: http://snowolf.iteye.com/blog/391931 |
static Digester |
sha1()
SHA1加密
例: SHA1加密:sha1().digest(data) SHA1加密并转为16进制字符串:sha1().digestHex(data) |
static String |
sha1(File dataFile)
SHA1加密文件,生成16进制SHA1字符串
|
static String |
sha1(InputStream data)
SHA1加密,生成16进制SHA1字符串
|
static String |
sha1(String data)
SHA1加密,生成16进制SHA1字符串
|
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 SecretKey generateKey(String algorithm)
SecretKeyalgorithm - 算法,支持PBE算法SecretKeypublic static SecretKey generateKey(String algorithm, byte[] key)
SecretKeyalgorithm - 算法key - 密钥SecretKeypublic static SecretKey generateDESKey(String algorithm, byte[] key)
SecretKeyalgorithm - PBE算法key - 密钥SecretKeypublic static SecretKey generatePBEKey(String algorithm, char[] key)
SecretKeyalgorithm - PBE算法key - 密钥SecretKeypublic static PrivateKey generatePrivateKey(String algorithm, byte[] key)
algorithm - 算法key - 密钥PrivateKeypublic static PrivateKey generatePrivateKey(KeyStore keyStore, String alias, char[] password)
keyStore - KeyStorealias - 别名password - 密码PrivateKeypublic static PublicKey generatePublicKey(String algorithm, byte[] key)
algorithm - 算法key - 密钥PublicKeypublic static KeyPair generateKeyPair(String algorithm)
algorithm - 非对称加密算法KeyPairpublic static KeyPair generateKeyPair(String algorithm, int keySize)
algorithm - 非对称加密算法keySize - 密钥模(modulus )长度KeyPairpublic static KeyPair generateKeyPair(String algorithm, int keySize, byte[] seed)
algorithm - 非对称加密算法keySize - 密钥模(modulus )长度seed - 种子KeyPairpublic static Signature generateSignature(AsymmetricAlgorithm asymmetricAlgorithm, DigestAlgorithm digestAlgorithm)
asymmetricAlgorithm - AsymmetricAlgorithm 非对称加密算法digestAlgorithm - DigestAlgorithm 摘要算法Signaturepublic static KeyStore readJKSKeyStore(InputStream in, char[] password)
in - InputStream 如果想从文件读取.keystore文件,使用new BufferedInputStream(new FileInputStream(file));读取password - 密码KeyStorepublic static KeyStore readKeyStore(String type, InputStream in, char[] password)
type - 类型in - InputStream 如果想从文件读取.keystore文件,使用new BufferedInputStream(new FileInputStream(file));读取password - 密码KeyStorepublic static Certificate readX509Certificate(InputStream in, char[] password)
in - InputStream 如果想从文件读取.cer文件,使用new BufferedInputStream(new FileInputStream(file));读取password - 密码KeyStorepublic static Certificate readCertificate(String type, InputStream in, char[] password)
type - 类型in - InputStream 如果想从文件读取.cer文件,使用new BufferedInputStream(new FileInputStream(file));读取password - 密码KeyStorepublic static Certificate getCertificate(KeyStore keyStore, String alias)
keyStore - KeyStorealias - 别名Certificatepublic static SymmetricCriptor aes()
SymmetricCriptor对象或者使用相同KEYpublic static SymmetricCriptor aes(byte[] key)
key - 密钥SymmetricCriptorpublic static SymmetricCriptor des()
SymmetricCriptor对象或者使用相同KEYpublic static SymmetricCriptor des(byte[] key)
key - 密钥SymmetricCriptorpublic static Digester md5()
Digesterpublic static String md5(InputStream data)
public static Digester sha1()
Digesterpublic static String sha1(InputStream data)
public static HMac hmacMd5(byte[] key)
key - 加密密钥HMacpublic static HMac hmacMd5()
HMacpublic static HMac hmacSha1(byte[] key)
key - 加密密钥HMacCopyright © 2017. All rights reserved.