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

  • 相关阅读:
    推送(评论,点赞,关注)
    php组成数组
    week6 10 后端backend server和mongoDB通信
    week06 09 NodeJS Server as a RPCclient
    week06 08 postman 测试jsonrpc
    week06 07 创建RPC SERVER 换个镜像安装下载
    week05 06绑定滚动条 去抖动
    week05 05restful api
    week5 04 npm run build
    week5 03 continus loading news
  • 原文地址:https://www.cnblogs.com/caozyblogs/p/15578252.html
Copyright © 2011-2022 走看看