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

  • 相关阅读:
    asp.net在线压缩和解压缩的实现 VS2005
    Office组件配置
    您无权查看或编辑目前 F:\XXX 的权限设置;但是,您可以取得所有权或更改审核设置
    23条心灵寄语献给在创业一线的兄弟姐妹
    IIS 环境下 w3wp.exe 进程 CPU 占用过高的解决方案
    SQLServer修改表所有者
    走出软件作坊推荐
    Asp.net 的 服务器推技术 (Server Push)
    上海火车站售票点
    Newtonsoft.Json.dll 本地调用正常,服务器调用不正常
  • 原文地址:https://www.cnblogs.com/caozyblogs/p/15578252.html
Copyright © 2011-2022 走看看