public class AlgorithmService extends Object
This is the class for crypto algorithms rsa2048Encrypt, ecdsaVerify, aes256GCM, sha256
and random function.
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
SPEC_AES_GCM_NONCE_BYTE_LEN
AES_GCM specs: CTR used 12bytes nonce || 4 bytes counter
|
static int |
SPEC_AES_KEY_BYTE_LEN
AES256 key spec
|
| 构造器和说明 |
|---|
AlgorithmService() |
| 限定符和类型 | 方法和说明 |
|---|---|
static byte[] |
aes256GCM(int opmode,
byte[] key,
byte[] iv,
byte[] input) |
static boolean |
ecdsaVerify(ECPublicKey pubkey,
byte[] message,
byte[] sigval) |
static byte[] |
genAES256SecretKey() |
static void |
initJceSecurityPolicy() |
static byte[] |
random(int len) |
static byte[] |
rsa2048Encrypt(RSAPublicKey pubkey,
byte[] message) |
static byte[] |
sha256(byte[] msg) |
public static final int SPEC_AES_KEY_BYTE_LEN
public static final int SPEC_AES_GCM_NONCE_BYTE_LEN
public static void initJceSecurityPolicy()
throws CryptoException
CryptoExceptionpublic static byte[] rsa2048Encrypt(RSAPublicKey pubkey, byte[] message) throws CryptoException, InvalidKeyException, BadPaddingException
pubkey - the public keymessage - CryptoExceptionInvalidKeyExceptionBadPaddingExceptionpublic static boolean ecdsaVerify(ECPublicKey pubkey, byte[] message, byte[] sigval) throws SignatureException, InvalidKeyException, CryptoException
pubkey - bytes format for PublicKey, detail format is: <1 byte first
number LEN>message - content to be verify.sigval - as mychain, the length of signature is 65 bytes as (r,s,v). The method toCryptoExceptionSignatureExceptionInvalidKeyExceptionpublic static byte[] aes256GCM(int opmode,
byte[] key,
byte[] iv,
byte[] input)
throws CryptoException,
InvalidKeyException,
InvalidAlgorithmParameterException
opmode - 1 is encryption, 2 is decryption.key - 256-bit keyiv - 96-bit ivinput - plaintext or ciphertextCryptoExceptionInvalidKeyExceptionInvalidAlgorithmParameterExceptionpublic static byte[] genAES256SecretKey()
throws NoSuchAlgorithmException,
CryptoException
NoSuchAlgorithmExceptionCryptoExceptionpublic static byte[] sha256(byte[] msg)
msg - input messagepublic static byte[] random(int len)
len - number of random bytesCopyright © 2022. All rights reserved.