@@ -4,7 +4,7 @@ description: Node.js APIs from the node:crypto and node:tls modules are now avai
44products :
55 - workers
66date : 2025-04-08T14:00:00Z
7- hidden : true
7+ # hidden: true
88---
99
1010import { Render , PackageManagers , TypeScriptExample } from " ~/components" ;
@@ -24,10 +24,10 @@ The full [`node:crypto`](https://nodejs.org/api/crypto.html) API is now availabl
2424You can use it to verify and sign data:
2525
2626``` js
27- import { sign , verify } from ' node:crypto' ;
27+ import { sign , verify } from " node:crypto" ;
2828
29- const signature = sign (' sha256' , ' some data to sign' , env .PRIVATE_KEY );
30- console . log ( verify (' sha256' , ' some data to sign' , env .PUBLIC_KEY , signature);
29+ const signature = sign (" sha256" , " - data to sign- " , env .PRIVATE_KEY );
30+ const verified = verify (" sha256" , " - data to sign- " , env .PUBLIC_KEY , signature);
3131```
3232
3333Or, to encrypt and decrypt data:
@@ -58,12 +58,17 @@ import { connect } from "node:tls";
5858// ... in a request handler ...
5959const connectionOptions = { key: env .KEY , cert: env .CERT };
6060const socket = connect (url, connectionOptions, () => {
61- console .log (
62- " client connected" ,
63- socket .authorized ? " authorized" : " unauthorized" ,
64- );
65- stdin .pipe (socket);
66- stdin .resume ();
61+ if (socket .authorized ) {
62+ console .log (" Connection authorized" );
63+ }
64+ });
65+
66+ socket .on (" data" , (data ) => {
67+ console .log (data);
68+ });
69+
70+ socket .on (" end" , () => {
71+ console .log (" server ends connection" );
6772});
6873```
6974
0 commit comments