🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] ## C 示例 ``` //export encrypt_key func encrypt_key(pubkey string, plainText []byte) *C.char { ciphertext, _ := helper.EncryptBinaryMessageArmored(pubkey, plainText) return C.CString(ciphertext) } //export decrypt_key func decrypt_key(privateKey string, passphrase []byte, ciphertext string) *C.char { plaintext, _ := helper.DecryptBinaryMessageArmored(privateKey, passphrase, ciphertext) return C.CString(string(plaintext)) } ``` c 调用 ``` int main() { GoString pubkey={"abc",123}; GoSlice plainText={"my message22",12,12 }; char* ret= encrypt_key(pubkey,plainText); printf("%s\n",ret); GoString prikey = {"abc",123}; GoSlice passphrase = { "bigant.cn",9,9 }; GoString ciphertext = { ret, strlen(ret) }; char* ret2 =decrypt_key(prikey, passphrase, ciphertext); printf("解答:%s", ret2); return 0; } ``` 执行 gcc ``` gcc -o demo demo.c ./pgp.so && ./demo.exe ```