-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support signing and verification using ECDSA
Introduce the methods `crypto.subtle.sign()` and `crypto.subtle.verify()` to create and verify ECDSA signatures. Currently, only the combination of the algorithm `ECDSAinDERFormat` and `SHA-256` hash is supported. The algorithm `ECDSAinDERFormat` is similar to the `ECDSA` algorithm used in `SubtleCrypto`, with the distinction that signature is encoded in the DER format, diverging from the IEEE-P1363 format used in `SubtleCrypto`.
- Loading branch information
Showing
4 changed files
with
361 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import {contentView, crypto, Stack, tabris, TextView} from 'tabris'; | ||
|
||
const stack = Stack({stretch: true, spacing: 8, padding: 16, alignment: 'stretchX'}) | ||
.appendTo(contentView); | ||
tabris.onLog(({message}) => stack.append(TextView({text: message}))); | ||
|
||
(async function() { | ||
|
||
// Generate a key pair for signing and verifying | ||
const keyPair = await crypto.subtle.generateKey( | ||
{name: 'ECDSA', namedCurve: 'P-256'}, | ||
true, | ||
['sign', 'verify'] | ||
); | ||
|
||
// Sign a message | ||
const message = await new Blob(['Message']).arrayBuffer(); | ||
const signature = await crypto.subtle.sign( | ||
{name: 'ECDSAinDERFormat', hash: 'SHA-256'}, | ||
keyPair.privateKey, | ||
message | ||
); | ||
console.log('Signature:', new Uint8Array(signature).join(', ')); | ||
|
||
// Verify the signature | ||
const isValid = await crypto.subtle.verify( | ||
{name: 'ECDSAinDERFormat', hash: 'SHA-256'}, | ||
keyPair.publicKey, | ||
signature, message | ||
); | ||
console.log('Signature valid:', isValid); | ||
|
||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters