Open sjjia opened 2 years ago
#ifndef EM_PORT_API # if defined(__EMSCRIPTEN__) # include <emscripten.h> # if defined(__cplusplus) # define EM_PORT_API(rettype) extern "C" rettype EMSCRIPTEN_KEEPALIVE # else # define EM_PORT_API(rettype) rettype EMSCRIPTEN_KEEPALIVE # endif # else # if defined(__cplusplus) # define EM_PORT_API(rettype) extern "C" rettype # else # define EM_PORT_API(rettype) rettype # endif # endif #endif #include <openssl/rsa.h> #include <openssl/x509.h> #include <openssl/err.h> EM_PORT_API (int) generateKeypair() { RSA* rsa = RSA_new(); BIGNUM *bn = BN_new(); RSA* _keypair = NULL; int setRet = BN_set_word(bn, RSA_F4); int rsaRet = RSA_generate_key_ex(rsa, 1024, bn, NULL); printf("setRet = %d \n", setRet); printf("rsaRet = %d \n", rsaRet); if (setRet && rsaRet) { _keypair = rsa; printf("_keypair create success!! \n"); } if (bn) { BN_free(bn); } if (rsa && _keypair==NULL) { RSA_free(rsa); } return 1; }
<html> <head> <meta charset="utf-8"> <title>Emscripten:Export1</title> </head> <body> <script> Module = {}; Module.onRuntimeInitialized = function() { var ret = Module._generateKeypair(); } </script> <script src="api.js"></script> </body> </html>
the version is openssl-1.1.1d, download from https://www.openssl.org/source/old/1.1.1/openssl-1.1.1d.tar.gz the Compiling step :
emcc -sLLD_REPORT_UNDEFINED --no-entry -std=c++11 -s USE_PTHREADS -sMAIN_MODULE api.cpp openssl/libcrypto.a openssl/libssl.a api.js
When running the demo,the funtion RSA_generate_key_ex(rsa, 1024, bn, NULL) returns 0.
I don't know which step is wrong , Help Me!!!
anyone know this question?
marking as inactive, will be closed at the end of 3.4 dev barring further input
C++ code:
apiTest.html code
Compiling openSSL to WebAssembly on Mac
the version is openssl-1.1.1d, download from https://www.openssl.org/source/old/1.1.1/openssl-1.1.1d.tar.gz the Compiling step :
make api.js by emcc
When running the demo,the funtion RSA_generate_key_ex(rsa, 1024, bn, NULL) returns 0.![image](https://user-images.githubusercontent.com/39543586/182291961-8c763f4d-668c-4882-9254-8fabac8902ab.png)
I don't know which step is wrong , Help Me!!!