一、C语言结构体
typedef structECCrefPublicKey_st { unsigned intbits; unsigned charx[ECCref_MAX_LEN]; unsigned chary[ECCref_MAX_LEN]; }ECCrefPublicKey; typedef structECCCipher_st { unsigned charx[ECCref_MAX_LEN]; unsigned chary[ECCref_MAX_LEN]; unsigned char M[32]; unsigned intL; unsigned char C[1024]; }ECCCipher; typedef ECCCipher ECCCIPHERBLOB; typedef ECCrefPublicKey ECCPUBLICKEYBLOB; typedef structSDF_ENVELOPEDKEYBLOB { unsigned longulAsymmAlgID; unsigned longulSymmAlgID; ECCCIPHERBLOB ECCCipherBlob; ECCPUBLICKEYBLOB PubKey; unsigned charcbEncryptedPriKey[ECCref_MAX_LEN]; }ENVELOPEDKEYBLOB, * PENVELOPEDKEYBLOB;
二、C语言接口
//生成ECC密钥对的保护结构 int SDF_Ext_GenEnvKeyPairBlob_ECC(void*hSessionHandle, unsigned intsymmAlgID, ECCrefPublicKey*pucPublicKey, ENVELOPEDKEYBLOB* pEnvelopedKeyBlob);
三、jna接口
int SDF_Ext_GenEnvKeyPairBlob_ECC(Pointer var1, NativeLong var2, ECCrefPublicKey.ByReference pucPublicKey, ENVELOPEDKEYBLOB.ByReference blob);
四、JNA结构体
class ENVELOPEDKEYBLOB extendsStructure { publicNativeLong ulAsymmAlgID; publicNativeLong ulSymmAlgID; publicECCCipher ECCCipherBlob; publicECCrefPublicKey PubKey; public byte[] cbEncryptedPriKey = new byte[64]; @Override protectedList getFieldOrder() { return Arrays.asList("ulAsymmAlgID", "ulSymmAlgID", "ECCCipherBlob", "PubKey", "cbEncryptedPriKey"); } public static class ByValue extends ENVELOPEDKEYBLOB implementsStructure.ByValue { publicByValue() { } } public static class ByReference extends ENVELOPEDKEYBLOB implementsStructure.ByReference { publicByReference() { } } }
public static class ECCCipher extendsStructure { public byte[] x = new byte[64]; public byte[] y = new byte[64]; public byte[] M = new byte[32]; public intL; public byte[] C = new byte[1024]; public static class ByValue extends ECCCipher implementsStructure.ByValue { publicByValue() { } } public static class ByReference extends ECCCipher implementsStructure.ByReference { publicByReference() { } } }
class ECCrefPublicKey extendsStructure { public intbits; public byte[] x = new byte[64]; public byte[] y = new byte[64]; @Override protected List<String>getFieldOrder() { return Arrays.asList(new String[] {"bits", "x","y"}); } @Override publicString toString() { return JSON.toJSONString(this); } public static class ByValue extends ECCrefPublicKey implementsStructure.ByValue { publicByValue() { } } public static class ByReference extends ECCrefPublicKey implementsStructure.ByReference { publicByReference() { } } }
五、jna调用demo
TestSDF_API.TestCLibrary.ECCCipher ECCCipherBlob = newTestSDF_API.TestCLibrary.ECCCipher(); TestSDF_API.TestCLibrary.ECCrefPublicKey pubKey = newTestSDF_API.TestCLibrary.ECCrefPublicKey(); TestSDF_API.TestCLibrary.ENVELOPEDKEYBLOB.ByReference pEnvelopedKeyBolb = newTestSDF_API.TestCLibrary.ENVELOPEDKEYBLOB.ByReference(); pEnvelopedKeyBolb.setECCCipherBlob(ECCCipherBlob); pEnvelopedKeyBolb.setPubKey(pubKey); pEnvelopedKeyBolb.setCbEncryptedPriKey(new byte[64]); rv = api.Test_SDF_Ext_GenEnvKeyPairBlob_ECC(hSessionHandle, sm4, EncPubKey, pEnvelopedKeyBolb);
搞定。
需要详细教程的加QQ:1059585163