I wanted to give encryption to a string before storing it in smart contract.
For example I have "hello" its 256 equivalent should be "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"
Please note that both input and output should be of type sp.TString
Below is a failed attempt to do so. It will help you understand what I am trying to do.
import smartpy as sp class Try(sp.Contract): def __init__(self): self.init(mystr = sp.string("")) @sp.entry_point def encypt(self,params): self.data.mystr = sp.sha256(params.key) @sp.add_test(name="try") def test(): obj = Try() scenario = sp.test_scenario() scenario += obj scenario += obj.encypt(key="hello")
Thanks in advance.