The following piece of code returns "does not match!" error:
pub, priv := GenerateKeyPair(2048)
ct1 := EncryptWithPublicKey([]byte("abc"), pub)
err := stub.PutState("ct", ct1)
ct2 := stub.GetState("ct")
if string(ct1[:]) != string(ct2[:]) {
return shim.Error("does not match!") //error returned
}
pt := DecryptWithPrivateKey(ct2, priv)
RSA library used: https://gist.github.com/miguelmota/3ea9286bd1d3c2a985b67cac4ba2130a
If the string comparison part is commented out, then the decryption function returns the error "crypto/rsa decryption error".
The following code works perfectly:
pub, priv := GenerateKeyPair(2048)
ct := EncryptWithPublicKey([]byte("abc"), pub)
pt := DecryptWithPrivateKey(ct, priv)