eos icon indicating copy to clipboard operation
eos copied to clipboard

how to sign a message with signature algorithm in smart contract?

Open Danilo0120 opened this issue 8 years ago • 6 comments

such as RSA 、DSS、 Elliptic curve

Danilo0120 avatar Oct 10 '18 03:10 Danilo0120

@taokayan

Danilo0120 avatar Oct 10 '18 03:10 Danilo0120

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 avatar Oct 10 '18 06:10 taokayan

@taokayan Well, I see. Thanks

Danilo0120 avatar Oct 10 '18 14:10 Danilo0120

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 avatar Oct 10 '18 18:10 jgiszczak

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 ??

Danilo0120 avatar Oct 11 '18 03:10 Danilo0120

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.

jgiszczak avatar Oct 11 '18 19:10 jgiszczak