类 URsa
java.lang.Object
com.gdxsoft.easyweb.utils.URsa
RSA工具类
- 作者:
- admin
-
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明byte[]Decryptionbyte[]Decryption (Using BC)byte[]decryptJava(byte[] encryptData, Key key) Decryption (Using java)byte[]decryptPrivate(byte[] encryptData) 私匙解密byte[]decryptPrivate(String base64EncryptData) 私匙解密byte[]decryptPublic(byte[] encryptData) 公匙解密byte[]decryptPublic(String base64EncryptData) 公匙解密byte[]digestMessage(byte[] data) Create data digest(Using java.security or BC According to usingBc parameter)byte[]digestMessageBc(byte[] data) Create data digest(Using BC)byte[]digestMessageJava(byte[] data) Create data digest(Using java.security)byte[]Encryption (Using java.security or BC According to usingBc parameter)byte[]Encryption (Using BC)byte[]encryptJava(byte[] data, Key key) Encryption (Using java.security)byte[]encryptPrivate(byte[] data) Encrypt the data with private keybyte[]encryptPublic(byte[] data) Encrypt the data with public keyvoidgenerateRsaKeys(int keySize) Create new public/private key摘要算法获取私匙获取公匙算法initPrivateDerKey(String derPrivateKeyFilePath) Initialize the private key with DER fileinitPrivateKey(byte[] keyBytes) Initialize the private key (DER format)initPrivateKey(String privateKeyFilePath) Initialize the private key with the private key file(.DER or .PEM)initPrivatePemKey(String pemPrivateKeyFilePath) Initialize the private key with the PEM format fileinitPublicDerKey(byte[] keyBytes) Initialize the public key with the keyinitPublicDerKey(String derPublicKeyFilePath) Initialize the public key with the key file(DER)initPublicKey(String publicKeyFilePath) Initialize the public key with the key file(DER/PEM)initPublicPemKey(String pemPublicKeyFilePath) Initialize the public key with the key file(PEM)booleanUsing java.security or BC for encryption/decryption according to parameter usingBc输出pem格式私匙输出 pem格式公匙byte[]readPemKey(String pemKeyFilePath) Convert the The PEM key file to the key buffvoidsetDigestAlgorithm(String digestAlgorithm) 摘要算法voidsetPrivateKey(RSAPrivateKey privateKey) 设置私匙voidsetPublicKey(RSAPublicKey publicKey) 设置公匙voidsetSignAlgorithm(String signAlgorithm) 算法voidsetUsingBc(boolean usingBc) Using java.security or BC for encryption/decryption according to parameter usingBcbyte[]sign(byte[] data) RSA signing (Using java.security or BC According to usingBc parameter)signBase64(byte[] data) RSA Sign the data and returns the base64 encoded signed databyte[]signBc(byte[] data) RSA signing(Using BC)byte[]signJava(byte[] data) RSA signing (Using java.secruity)booleanverify(byte[] data, byte[] sign) Verification the RSA digital signature (Using java.security or BC According to usingBc parameter)booleanverifyBase64(byte[] data, String base64Sign) Verification the RSA digital signature (Using java.security or BC According to usingBc parameter)booleanverifyBc(byte[] data, byte[] sign) Verification the RSA digital signature(USING BC)booleanverifyJava(byte[] data, byte[] sign) Verification the RSA digital signature (Using java.security)
-
字段详细资料
-
构造器详细资料
-
URsa
public URsa()sign: SHA256withRSA digest: sha-256 -
URsa
-
-
方法详细资料
-
generateRsaKeys
Create new public/private key- 参数:
keySize- This is an algorithm-specific metric, such as modulus length, specified in number of bits.- 抛出:
NoSuchAlgorithmException
-
readPemKey
Convert the The PEM key file to the key buff- 参数:
pemKeyFilePath- The PEM key file path- 返回:
- the converted key data
- 抛出:
IOException
-
initPublicKey
public RSAPublicKey initPublicKey(String publicKeyFilePath) throws NoSuchAlgorithmException, InvalidKeySpecException, IOException Initialize the public key with the key file(DER/PEM)- 参数:
publicKeyFilePath- the key file(DER/PEM) path- 返回:
- the public key
- 抛出:
NoSuchAlgorithmExceptionInvalidKeySpecExceptionIOException
-
initPublicPemKey
public RSAPublicKey initPublicPemKey(String pemPublicKeyFilePath) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException Initialize the public key with the key file(PEM)- 参数:
pemPublicKeyFilePath- the key file(PEM) path- 返回:
- the public key
- 抛出:
IOExceptionInvalidKeySpecExceptionNoSuchAlgorithmException
-
initPublicDerKey
public RSAPublicKey initPublicDerKey(String derPublicKeyFilePath) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException Initialize the public key with the key file(DER)- 参数:
derPublicKeyFilePath- the key file(DER) path- 返回:
- the public key
- 抛出:
IOExceptionNoSuchAlgorithmExceptionInvalidKeySpecException
-
initPublicDerKey
public RSAPublicKey initPublicDerKey(byte[] keyBytes) throws NoSuchAlgorithmException, InvalidKeySpecException Initialize the public key with the key- 参数:
keyBytes- the key data- 返回:
- the public key
- 抛出:
NoSuchAlgorithmExceptionInvalidKeySpecException
-
initPrivateKey
public RSAPrivateKey initPrivateKey(String privateKeyFilePath) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException Initialize the private key with the private key file(.DER or .PEM)- 参数:
privateKeyFilePath- the private key file- 返回:
- the private key
- 抛出:
IOExceptionInvalidKeySpecExceptionNoSuchAlgorithmException
-
initPrivatePemKey
public RSAPrivateKey initPrivatePemKey(String pemPrivateKeyFilePath) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException Initialize the private key with the PEM format file- 参数:
pemPrivateKeyFilePath- the private key PEM format file- 返回:
- The private key
- 抛出:
IOExceptionInvalidKeySpecExceptionNoSuchAlgorithmException
-
initPrivateDerKey
public RSAPrivateKey initPrivateDerKey(String derPrivateKeyFilePath) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException Initialize the private key with DER file- 参数:
derPrivateKeyFilePath- The DER file path- 返回:
- the private key
- 抛出:
IOExceptionInvalidKeySpecExceptionNoSuchAlgorithmException
-
initPrivateKey
public RSAPrivateKey initPrivateKey(byte[] keyBytes) throws NoSuchAlgorithmException, InvalidKeySpecException Initialize the private key (DER format)- 参数:
keyBytes- the DER key- 返回:
- the private key
- 抛出:
NoSuchAlgorithmExceptionInvalidKeySpecException
-
signBase64
RSA Sign the data and returns the base64 encoded signed data- 参数:
data- the source data- 返回:
- the base64 encoded signed data
- 抛出:
InvalidKeyExceptionNoSuchAlgorithmExceptionSignatureExceptionException
-
sign
RSA signing (Using java.security or BC According to usingBc parameter)- 参数:
data- the source data- 返回:
- signature the signed data
- 抛出:
Exception
-
signJava
public byte[] signJava(byte[] data) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException RSA signing (Using java.secruity)- 参数:
data- the source data- 返回:
- signature the signed data
- 抛出:
NoSuchAlgorithmExceptionInvalidKeyExceptionSignatureExceptionException
-
signBc
public byte[] signBc(byte[] data) throws IOException, org.bouncycastle.crypto.DataLengthException, org.bouncycastle.crypto.CryptoException RSA signing(Using BC)- 参数:
data- the source data- 返回:
- signature
- 抛出:
ExceptionIOExceptionorg.bouncycastle.crypto.DataLengthExceptionorg.bouncycastle.crypto.CryptoException
-
verifyBase64
Verification the RSA digital signature (Using java.security or BC According to usingBc parameter)- 参数:
data- the source database64Sign- sign the signature of the source data(base64)- 返回:
- verify result
- 抛出:
Exception
-
verify
Verification the RSA digital signature (Using java.security or BC According to usingBc parameter)- 参数:
data- the source datasign- the signature of the source data- 返回:
- verify result
- 抛出:
Exception
-
verifyJava
public boolean verifyJava(byte[] data, byte[] sign) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException Verification the RSA digital signature (Using java.security)- 参数:
data- the source datasign- the signature of the source data- 返回:
- verify result
- 抛出:
NoSuchAlgorithmExceptionInvalidKeyExceptionSignatureExceptionException
-
verifyBc
Verification the RSA digital signature(USING BC)- 参数:
data- the source datasign- the signature of the source data- 返回:
- verify result
- 抛出:
IOException
-
digestMessage
Create data digest(Using java.security or BC According to usingBc parameter)- 参数:
data- the source data- 返回:
- the digest result
- 抛出:
NoSuchAlgorithmException
-
digestMessageJava
Create data digest(Using java.security)- 参数:
data- the source data- 返回:
- the digest result
- 抛出:
NoSuchAlgorithmException
-
digestMessageBc
public byte[] digestMessageBc(byte[] data) Create data digest(Using BC)- 参数:
data- the source data- 返回:
- the digest result
-
encryptPublic
Encrypt the data with public key- 参数:
data- the plain data- 返回:
- the encryption data
- 抛出:
Exception
-
encryptPrivate
Encrypt the data with private key- 参数:
data- the plain data- 返回:
- the encryption data
- 抛出:
Exception
-
encrypt
Encryption (Using java.security or BC According to usingBc parameter)- 参数:
data- the plain datakey- publicKey / privateKey- 返回:
- the encryption data
- 抛出:
Exception
-
encryptJava
public byte[] encryptJava(byte[] data, Key key) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException Encryption (Using java.security)- 参数:
data- the plain datakey- publicKey/ privateKey- 返回:
- the encryption data
- 抛出:
NoSuchAlgorithmExceptionNoSuchPaddingExceptionInvalidKeyExceptionIllegalBlockSizeExceptionBadPaddingException
-
encryptBc
public byte[] encryptBc(byte[] data, Key key) throws IOException, org.bouncycastle.crypto.InvalidCipherTextException Encryption (Using BC)- 参数:
data- the plain datakey- publicKey/ privateKey- 返回:
- the encryption data
- 抛出:
IOExceptionorg.bouncycastle.crypto.InvalidCipherTextException
-
decryptPublic
公匙解密- 参数:
base64EncryptData- base64加密数据- 返回:
- 解密数据
- 抛出:
IOExceptionInvalidKeyExceptionNoSuchAlgorithmExceptionNoSuchPaddingExceptionIllegalBlockSizeExceptionBadPaddingExceptionException
-
decryptPublic
公匙解密- 参数:
encryptData- 加密数据- 返回:
- 解密数据
- 抛出:
InvalidKeyExceptionNoSuchAlgorithmExceptionNoSuchPaddingExceptionIllegalBlockSizeExceptionBadPaddingExceptionException
-
decryptPrivate
私匙解密- 参数:
base64EncryptData- base64加密数据- 返回:
- 解密数据
- 抛出:
IOExceptionInvalidKeyExceptionNoSuchAlgorithmExceptionNoSuchPaddingExceptionIllegalBlockSizeExceptionBadPaddingExceptionException
-
decryptPrivate
私匙解密- 参数:
encryptData- 加密数据- 返回:
- 解密数据
- 抛出:
InvalidKeyExceptionNoSuchAlgorithmExceptionNoSuchPaddingExceptionIllegalBlockSizeExceptionBadPaddingExceptionException
-
decrypt
Decryption- 参数:
encryptData- Encrypted datakey- publicKey / privateKey- 返回:
- the plain data
- 抛出:
Exception
-
decryptJava
public byte[] decryptJava(byte[] encryptData, Key key) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException Decryption (Using java)- 参数:
encryptData- Encrypted datakey- publicKey / privateKey- 返回:
- the plain data
- 抛出:
NoSuchPaddingExceptionNoSuchAlgorithmExceptionInvalidKeyExceptionBadPaddingExceptionIllegalBlockSizeExceptionException
-
decryptBc
public byte[] decryptBc(byte[] encryptData, Key key) throws IOException, org.bouncycastle.crypto.InvalidCipherTextException Decryption (Using BC)- 参数:
encryptData- Encrypted datakey- PublicKey/ PrivateKey- 返回:
- the plain data
- 抛出:
IOExceptionorg.bouncycastle.crypto.InvalidCipherTextException
-
privateKeyToPem
输出pem格式私匙- 返回:
- pem格式私匙
- 抛出:
IOException
-
publicKeyToPem
输出 pem格式公匙- 返回:
- pem格式公匙
- 抛出:
IOException
-
getPrivateKey
获取私匙- 返回:
- 私匙
-
getPublicKey
获取公匙- 返回:
- 公匙
-
getSignAlgorithm
算法- 返回:
- 算法
-
setSignAlgorithm
算法- 参数:
signAlgorithm- 算法
-
getDigestAlgorithm
摘要算法- 返回:
- 摘要算法
-
setDigestAlgorithm
摘要算法- 参数:
digestAlgorithm- 摘要算法
-
setPrivateKey
设置私匙- 参数:
privateKey-
-
setPublicKey
设置公匙- 参数:
publicKey-
-
isUsingBc
public boolean isUsingBc()Using java.security or BC for encryption/decryption according to parameter usingBc- 返回:
- true= BC, false= java.security
-
setUsingBc
public void setUsingBc(boolean usingBc) Using java.security or BC for encryption/decryption according to parameter usingBc- 参数:
usingBc- true= BC, false= java.security
-