Encrypt data using c# and decrypt it using openssl api, why there are lots of trashy padding at the end of decrypted data? -


i using rsa(1024) encrypt/decrypt strings. encryption implemented using public key , written in c#, , decryption implementation c. encrypt string:

86afaecb-c211-4d55-8e90-2b715d6d64b9

and write encrypted data file. then, using openssl api read encrypted data file , decrypt it. however, got output as:

86afaecb-c211-4d55-8e90-2b715d6d64b9oehebjq8fo1amdnor1d3blupyq9wjbaov+m/wvnyzyr pjbkoskoj+4lanpt+spkfk81nsnqebhbjgao4ehnu+pmwl9

it seems there trashy padding @ end of original string. why occurs? , how solve problem?

some code snippet shown below:

// encrypt {     string plaindata = “86afaecb-c211-4d55-8e90-2b715d6d64b9”;     rsacryptoserviceprovider rsa = new rsacryptoserviceprovider();     rsa.importparameters(parapub);     byte[] testdata = encoding.utf8.getbytes(plaindata);     byte[] encrypteddata = rsa.encrypt(testdata, true);     filestream pfilestream = null;     string filename = "encrypteddata.dat";     pfilestream = new filestream(filename, filemode.openorcreate);     pfilestream.write(encrypteddata, 0, encrypteddata.length);     ... }  // decrypt {     char *encrypt = malloc(rsa_size(privatekey));     file *out = fopen("encrypteddata.dat", "r");     int encrypt_len = fread(encrypt, sizeof(*encrypt), rsa_size(privatekey), out);     fclose(out);      decrypt = malloc(encrypt_len);     if(rsa_private_decrypt(encrypt_len,                            (unsigned char*)encrypt,                            (unsigned char*)decrypt,                            privatekey, rsa_pkcs1_oaep_padding) == -1) {         // error handle     }      printf("decrypted message: %s\n", decrypt); } 

i solve problem initializing decrypt using "memset(decrypt, 0, encrypt_len);" after "decrypt = malloc(encrypt_len);". thx everyone.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -