Crypto.doSign - corda

corda / net.corda.core.crypto / Crypto / doSign

# doSign

`@JvmStatic fun doSign(privateKey: PrivateKey, clearData: ByteArray): ByteArray`

Generic way to sign ByteArray data with a PrivateKey. Strategy on on identifying the actual signing scheme is based on the PrivateKey type, but if the schemeCodeName is known, then better use doSign(signatureScheme: String, privateKey: PrivateKey, clearData: ByteArray).

### Parameters

`privateKey` - the signer's PrivateKey.

`clearData` - the data/message to be signed in ByteArray form (usually the Merkle root).

### Exceptions

`IllegalArgumentException` - if the signature scheme is not supported for this private key.

`InvalidKeyException` - if the private key is invalid.

`SignatureException` - if signing is not possible due to malformed data or private key.

Return
the digital signature (in ByteArray) on the input message.

`@JvmStatic fun doSign(schemeCodeName: String, privateKey: PrivateKey, clearData: ByteArray): ByteArray`

Generic way to sign ByteArray data with a PrivateKey and a known schemeCodeName String.

### Parameters

`schemeCodeName` - a signature scheme's code name (e.g. ECDSA_SECP256K1_SHA256).

`privateKey` - the signer's PrivateKey.

`clearData` - the data/message to be signed in ByteArray form (usually the Merkle root).

### Exceptions

`IllegalArgumentException` - if the signature scheme is not supported.

`InvalidKeyException` - if the private key is invalid.

`SignatureException` - if signing is not possible due to malformed data or private key.

Return
the digital signature (in ByteArray) on the input message.

`@JvmStatic fun doSign(signatureScheme: SignatureScheme, privateKey: PrivateKey, clearData: ByteArray): ByteArray`

Generic way to sign ByteArray data with a PrivateKey and a known Signature.

### Parameters

`signatureScheme` - a SignatureScheme object, retrieved from supported signature schemes, see Crypto.

`privateKey` - the signer's PrivateKey.

`clearData` - the data/message to be signed in ByteArray form (usually the Merkle root).

### Exceptions

`IllegalArgumentException` - if the signature scheme is not supported for this private key.

`InvalidKeyException` - if the private key is invalid.

`SignatureException` - if signing is not possible due to malformed data or private key.

Return
the digital signature (in ByteArray) on the input message.

`@JvmStatic fun doSign(keyPair: KeyPair, signableData: SignableData): TransactionSignature`

Generic way to sign SignableData objects with a PrivateKey. SignableData is a wrapper over the transaction's id (Merkle root) in order to attach extra information, such as a timestamp or partial and blind signature indicators.

### Parameters

`keyPair` - the signer's KeyPair.

`signableData` - a SignableData object that adds extra information to a transaction.

### Exceptions

`IllegalArgumentException` - if the signature scheme is not supported for this private key.

`InvalidKeyException` - if the private key is invalid.

`SignatureException` - if signing is not possible due to malformed data or private key.

Return
a TransactionSignature object than contains the output of a successful signing, signer's public key and the signature metadata.