how to sign a message with signature algorithm in smart contract?
such as RSA 、DSS、 Elliptic curve
@taokayan
There's no direct smart contract api for signing. If you really want to sign in the smart contract you need to include the implementation of RSA/DSS/ECC into your contract. However you can use "require_auth" to ensure some account must sign certain transactions.
@taokayan Well, I see. Thanks
Odds are you should not be attempting to sign within a contract. Signing requires a private key. To successfully sign, you would need to embed your private key in the contract source code, where it can be extracted by anyone. You would have no control over its use.
Odds are you should not be attempting to sign within a contract. Signing requires a private key. To successfully sign, you would need to embed your private key in the contract source code, where it can be extracted by anyone. You would have no control over its use.
@jgiszczak In fact, I want to use RSA Algorithm to encrypt a secret key with other node A's EOS public key and send the ciphertext to A, A decrypt the ciphertext with its private key , how should i do ??
As taokayan said, the crypto API provided to contracts does not include access to the RSA algorithm. You would need to statically compile a version of it to WASM and link it into your contract in order to perform the desired encryption.
What you wish to do is still completely insecure. You can not generate a secret key within a contract in a secure way, as the chain is deterministic, which means anyone could generate the same key simply by rerunning your contract action with the same starting conditions. You can not submit a plaintext secret key on a contract action without exposing it to all users of the chain, as contract actions are logged by many nodes.
To transmit an encrypted secret key to some destination, you must pre-encrypt the key entirely off the chain using the account's public key, before ever submitting a transaction. Then you may create a transaction with the pre-encrypted key in it for provable delivery of some data at some time. Since the data is encrypted, the proof does not extend to the contents, as only the intended recipient can decrypt the data being sent.