zoukankan      html  css  js  c++  java
  • JNA结构体嵌套如何调用

    一、C语言结构体

    typedef struct ECCrefPublicKey_st {
    unsigned int bits;
    unsigned char x[ECCref_MAX_LEN];
    unsigned char y[ECCref_MAX_LEN];
    }ECCrefPublicKey;
    
    
    
    typedef struct ECCCipher_st {
    unsigned char x[ECCref_MAX_LEN];
    unsigned char y[ECCref_MAX_LEN];
    unsigned char M[32];
    unsigned int L;
    unsigned char C[1024];
    }ECCCipher;
    
    
    
    typedef ECCCipher ECCCIPHERBLOB;
    typedef ECCrefPublicKey ECCPUBLICKEYBLOB;
    
    
    
    typedef struct SDF_ENVELOPEDKEYBLOB {
    unsigned long ulAsymmAlgID;
    unsigned long ulSymmAlgID;
    ECCCIPHERBLOB ECCCipherBlob;
    ECCPUBLICKEYBLOB PubKey;
    unsigned char cbEncryptedPriKey[ECCref_MAX_LEN];
    }ENVELOPEDKEYBLOB, * PENVELOPEDKEYBLOB;

    二、C语言接口

    //生成ECC密钥对的保护结构
    int SDF_Ext_GenEnvKeyPairBlob_ECC(void* hSessionHandle,
    unsigned int symmAlgID,
    ECCrefPublicKey* pucPublicKey,
    ENVELOPEDKEYBLOB* pEnvelopedKeyBlob);

    三、jna接口

    int SDF_Ext_GenEnvKeyPairBlob_ECC(Pointer var1, NativeLong var2, ECCrefPublicKey.ByReference pucPublicKey, ENVELOPEDKEYBLOB.ByReference blob);

    四、JNA结构体

     class ENVELOPEDKEYBLOB extends Structure {
                public NativeLong ulAsymmAlgID;
                public NativeLong ulSymmAlgID;
                public ECCCipher ECCCipherBlob;
                public ECCrefPublicKey PubKey;
                public byte[] cbEncryptedPriKey = new byte[64];
    
                @Override
                protected List getFieldOrder() {
                    return Arrays.asList("ulAsymmAlgID", "ulSymmAlgID", "ECCCipherBlob", "PubKey", "cbEncryptedPriKey");
    
                }
    
                public static class ByValue extends ENVELOPEDKEYBLOB implements Structure.ByValue {
                    public ByValue() {
                    }
                }
    
                public static class ByReference extends ENVELOPEDKEYBLOB implements Structure.ByReference {
                    public ByReference() {
                    }
                }
            }
     
    public static class ECCCipher extends Structure {
                public byte[] x = new byte[64];
                public byte[] y = new byte[64];
                public byte[] M = new byte[32];
                public int L;
                public byte[] C = new byte[1024];
    
                public static class ByValue extends ECCCipher implements Structure.ByValue {
                    public ByValue() {
                    }
                }
    
                public static class ByReference extends ECCCipher implements Structure.ByReference {
                    public ByReference() {
                    }
                }
            }
    class ECCrefPublicKey extends Structure {
                public int bits;
                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
                public String toString() {
                    return JSON.toJSONString(this);
                }
    
                public static class ByValue extends ECCrefPublicKey implements Structure.ByValue {
                    public ByValue() {
    
                    }
                }
    
                public static class ByReference extends ECCrefPublicKey implements Structure.ByReference {
                    public ByReference() {
    
                    }
                }
            }

    五、jna调用demo

    TestSDF_API.TestCLibrary.ECCCipher ECCCipherBlob = new TestSDF_API.TestCLibrary.ECCCipher();
    TestSDF_API.TestCLibrary.ECCrefPublicKey pubKey = new TestSDF_API.TestCLibrary.ECCrefPublicKey();
    TestSDF_API.TestCLibrary.ENVELOPEDKEYBLOB.ByReference pEnvelopedKeyBolb = new TestSDF_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

  • 相关阅读:
    Jquery实现Gridview全选功能
    SQL Server日期计算
    避免表格table被撑开变形的CSS代码实例
    oracle游标使用
    最短路径算法及应用
    Jquery实现GridView隔行变色,鼠标经过变色,单击或者选中变色
    【项目】项目109
    【项目】项目107
    【项目】项目111
    【项目】项目110
  • 原文地址:https://www.cnblogs.com/caozyblogs/p/15578252.html
Copyright © 2011-2022 走看看