public class HSMInterface
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
ALGORITHM_RSA |
static int |
CERT_TYPE_APP_ROOT |
static int |
CERT_TYPE_COMMUNICATE |
static int |
CERT_TYPE_OWNER |
static int |
CERT_TYPE_PUBLIC_KEY |
static int |
FORMAT_DER |
static int |
FORMAT_PEM |
Constructor and Description |
---|
HSMInterface() |
Modifier and Type | Method and Description |
---|---|
static int |
close()
close the device
|
static int |
deleteCertificate(int certType,
java.lang.String alias)
Remove the certificate of the given alias.
|
static int |
deleteKeyPair(java.lang.String aliasPrivateKey)
Remove the key pair of the given alias.
|
static int |
deleteUnionPayPrivateKey()
Delete UnionPay private key.
|
static int |
doRSADecrypt(java.lang.String aliasPrivateKey,
byte[] bufCipher,
byte[] bufResult,
int resMaxLength)
Do decryption by the given private key.
|
static int |
doRSAEncrypt(java.lang.String aliasPrivateKey,
byte[] bufPlain,
byte[] bufResult,
int resMaxLength)
Do encryption by the given private key.
|
static int |
enableSensor(int key)
Enable external sensor.
|
static int |
existMethod(java.lang.String methodName)
Get x509 crl
|
static int |
generateCSR(java.lang.String aliasPrivateKey,
java.lang.String commName,
byte[] bufResult,
int resMaxLength)
Generate the CSR for given private key.
|
static int |
generateKeyPair(java.lang.String alias,
int algorithm,
int keySize)
Request security module to generate a key pair inside the module.
|
static int |
generatePINPadCSR(byte[] bufResult,
int length)
Generate csr for pinpad inject key.
|
static int |
getCertificate(int certType,
java.lang.String alias,
byte[] bufCert,
int bufMaxLength,
int dataFormat)
Get the certificate data.
|
static int |
getCrl(java.lang.String pLabel,
byte[] pBuffer)
Get x509 crl
|
static int |
getFlashID(byte[] flashIDBuffer)
Get flash id.
|
static int |
getRandom(byte[] bufRandom,
int length)
Get the real random buffer from safe module.
|
static int |
injectPublicKeyCertificate(java.lang.String alias,
java.lang.String aliasPrivateKey,
byte[] bufCert,
int bufLength,
int dataFormat)
Inject the certificate of the existing key pair.
|
static int |
injectRootCertificate(int certType,
java.lang.String alias,
byte[] bufCert,
int bufLength,
int dataFormat)
Inject the root certificates to security module.
All the certificate must signed by the terminal's owner certificate. |
static boolean |
isKeyExist(int nKeyID,
int nKeyType)
Query key whether exist or not.
|
static boolean |
isOpened()
if open or not.
|
static int |
isTampered()
Check the security module is tampered or not.
|
static int |
keyDecrypt(int nKeyID,
int nKeyType,
int nMode,
byte[] byteData,
byte[] pIV)
Key decrypt.
|
static int |
keyEncrypt(int nKeyID,
int nKeyType,
int nMode,
byte[] byteData,
byte[] pIV)
Key encrypt.
|
static int |
open()
Open the device.
Require one of the SAFE_MODULE_READONLY, SAFE_MODULE or SAFE_MODULE_RESET permission. |
static int |
queryCertCount(int certType)
Query the count of specific type certificate in the hardware secure module.
|
static int |
queryCertLabels(int certType,
byte[] bufLabels,
int length)
Query the lable of specific type certificate in the hardware secure module, every label separated by ':'.
|
static int |
queryCrlLabels(byte[] pLabel)
Query x509 crl labels
|
static int |
queryPrivateKeyCount()
Query the count of private key in the hardware secure module.
|
static int |
queryPrivateKeyLabels(byte[] bufLabels,
int length)
Query the lable of private key in the hardware secure module, every label separated by ':'.
|
static int |
resetSaveModule(java.lang.String pwd)
Reset the safe module.
|
static int |
saveCrl(java.lang.String pLabel,
byte[] pBuffer)
Save x509 crl
|
static int |
saveUnionPayPrivateKey(byte[] byteData,
int nDataLength)
Save UnionPay private key.
|
static int |
updateKey(int nKeyID,
int nKeyType,
byte[] byteData)
Update Key.
|
static int |
updateSM4Key(int nKeyID,
byte[] pKeyBuffer,
byte[] pSignature)
Update sm4 key
|
public static final int FORMAT_PEM
public static final int FORMAT_DER
public static final int CERT_TYPE_OWNER
public static final int CERT_TYPE_PUBLIC_KEY
public static final int CERT_TYPE_APP_ROOT
public static final int CERT_TYPE_COMMUNICATE
public static final int ALGORITHM_RSA
public static int open()
public static int close()
public static int isTampered()
public static int getRandom(byte[] bufRandom, int length)
This method requires SAFE_MODULE_READONLY or SAFE_MODULE permission.
bufRandom
- the buffer to store random bytes.length
- the length of the buffer.public static int generateKeyPair(java.lang.String alias, int algorithm, int keySize)
alias:
- the alias of the private key.algorithm:
- the algorithm of the key pair. Currently, only ALGORITHM_RSA is supported.keySize:
- the bit size of the key. Currently, only 2048 is supported.public static int injectPublicKeyCertificate(java.lang.String alias, java.lang.String aliasPrivateKey, byte[] bufCert, int bufLength, int dataFormat)
alias:
- the alias of the certificate.aliasPrivateKey:
- the alias of the key pair, usually it's the private key's alias.bufCert:
- the data of the certificate.bufLength:
- the length of the data buffer.enforceCalliUpdateServicengPermissiondataFormat:
- the format of the buffer, Currently, only "PEM" is supported.public static int injectRootCertificate(int certType, java.lang.String alias, byte[] bufCert, int bufLength, int dataFormat)
certType:
- the certificate type, could be CERT_TYPE_OWNER, CERT_TYPE_APP_ROOT or CERT_TYPE_COMMUNICATE.alias:
- the alias of the certificate.getCertificatebufCert:
- the data of the certificate.bufLength:
- the length of the data buffer.dataFormat:
- the format of the buffer, Currently, only FORMAT_PEM is supported.public static int getCertificate(int certType, java.lang.String alias, byte[] bufCert, int bufMaxLength, int dataFormat)
certType:
- the certificate type, could be CERT_TYPE_OWNER, CERT_TYPE_PUBLIC_KEY, CERT_TYPE_APP_ROOT or CERT_TYPE_COMMUNICATE.alias:
- the alias of the certificatebufCert:
- the output buffer to store the certificate PEM data.bufMaxLength:
- the max length of the result buffer.dataFormat:
- the format of the buffer, Currently, only FORMAT_PEM is supported.public static int deleteCertificate(int certType, java.lang.String alias)
certType:
- the certificate type, could be CERT_TYPE_PUBLIC_KEY, CERT_TYPE_APP_ROOT or CERT_TYPE_COMMUNICATE.alias:
- the alias of the certificatepublic static int deleteKeyPair(java.lang.String aliasPrivateKey)
aliasPrivateKey:
- the alias of the private key.public static int generateCSR(java.lang.String aliasPrivateKey, java.lang.String commName, byte[] bufResult, int resMaxLength)
alias:
- the alias of the private keyaliasPrivateKey:
- the alias of the private keycommonName:
- the DN of the commonNamebufResult:
- the buffer to store the CSR data.resMaxLength:
- the max length of the result buffer.public static int doRSAEncrypt(java.lang.String aliasPrivateKey, byte[] bufPlain, byte[] bufResult, int resMaxLength)
aliasPrivateKey:
- the alias of the given private key.bufPlain:
- the buffer of the plain data.bufResult:
- the buffer for the output cipher data.resMaxLength:
- the max length of the output buffer.public static int doRSADecrypt(java.lang.String aliasPrivateKey, byte[] bufCipher, byte[] bufResult, int resMaxLength)
aliasPrivateKey:
- the alias of the given private key.bufCipher:
- the buffer of the cipher data.bufResult:
- the buffer for the output cipher data.resMaxLength:
- the max length of the output buffer.public static int queryPrivateKeyLabels(byte[] bufLabels, int length)
bufLabels:
- the buffer of the labels.length:
- the length of the output buffer.public static int queryPrivateKeyCount()
public static int queryCertLabels(int certType, byte[] bufLabels, int length)
bufLabels:
- the buffer of the labels.length:
- the length of the output buffer.public static int queryCertCount(int certType)
public static int resetSaveModule(java.lang.String pwd)
pwd:
- the password of resetpublic static int generatePINPadCSR(byte[] bufResult, int length)
bufResult:
- data buffer.length:
- length of data buffer.public static int enableSensor(int key)
key:
- indicate to enable which sensor, value must from 1 to 15.public static int saveUnionPayPrivateKey(byte[] byteData, int nDataLength)
byteData:
- key buffer.nDataLength:
- length of key buffer.public static int deleteUnionPayPrivateKey()
public static int updateKey(int nKeyID, int nKeyType, byte[] byteData) throws java.lang.NoSuchMethodException
nKeyID:
- key index, from 0 to 9.nKeyType:
- indicate the key type:SM4, DES,3DES or AES.byteData:
- key data.java.lang.NoSuchMethodException
public static int keyEncrypt(int nKeyID, int nKeyType, int nMode, byte[] byteData, byte[] pIV) throws java.lang.NoSuchMethodException
nKeyID:
- key index, from 0 to 9.nKeyType:
- indicate the key type:SM4, DES,3DES or AES.nMode:
- 0: ECB 1: CBC 2:CFB 3:OFBbyteData:
- plain text to be encryt.pIV:
- initialize vector.java.lang.NoSuchMethodException
public static int keyDecrypt(int nKeyID, int nKeyType, int nMode, byte[] byteData, byte[] pIV) throws java.lang.NoSuchMethodException
nKeyID:
- key index, from 0 to 9.nKeyType:
- indicate the key type:SM4, DES,3DES or AES.nMode:
- 0: ECB 1: CBC 2:CFB 3:OFBbyteData:
- plain text to be decryt.pIV:
- initialize vector.java.lang.NoSuchMethodException
public static boolean isKeyExist(int nKeyID, int nKeyType) throws java.lang.NoSuchMethodException
nKeyID:
- key index, from 0 to 9.nKeyType:
- indicate the key type:SM4, DES,3DES or AES.java.lang.NoSuchMethodException
public static int getFlashID(byte[] flashIDBuffer) throws java.lang.NoSuchMethodException
flashIDBuffer:
- data buffer.java.lang.NoSuchMethodException
public static boolean isOpened()
public static int updateSM4Key(int nKeyID, byte[] pKeyBuffer, byte[] pSignature) throws java.lang.NoSuchMethodException
nKeyID:
- key index, from 0 to 2.pKeyBuffer:
- key data.pSignature:
- signature data.
return value : >= 0 : success
< 0 : failjava.lang.NoSuchMethodException
public static int saveCrl(java.lang.String pLabel, byte[] pBuffer) throws java.lang.NoSuchMethodException
java.lang.NoSuchMethodException
public static int getCrl(java.lang.String pLabel, byte[] pBuffer) throws java.lang.NoSuchMethodException
java.lang.NoSuchMethodException
public static int existMethod(java.lang.String methodName)
public static int queryCrlLabels(byte[] pLabel) throws java.lang.NoSuchMethodException
pLabel:
- the labels of crl
return value : > 0 : success, return crl data length
<= 0 : failjava.lang.NoSuchMethodException