File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,19 +29,20 @@ natural syntax.
2929``` typescript
3030import {openssl } from ' @sourceregistry/node-openssl' ;
3131
32+
3233async function main() {
3334 // Generate a 2048-bit RSA private key
3435 const key = await openssl ` genpkey -algorithm RSA -outform PEM -pkeyopt rsa_keygen_bits:2048 ` .one ();
3536 console .log (' Private Key:\n ' , key .data );
3637 console .log (' SHA-256:' , key .sha256 );
3738
3839 // Generate a self-signed certificate
39- const cert = await openssl ` req -x509 -new -key <(echo " ${key . data }") -subj "/CN=localhost" -days 365 -outform PEM ` .one ();
40+ const cert = await openssl ` req -x509 -new -key ${key } -subj "/CN=localhost" -days 365 -outform PEM ` .one ();
4041 console .log (' Certificate:\n ' , cert .data );
4142 console .log (' Is Certificate Chain?' , cert .isChain );
4243}
4344
44- main ();
45+ main (). catch ( console . error ) ;
4546```
4647
4748### Working with Output Buffers
Original file line number Diff line number Diff line change 1+ import { openssl } from "../src" ;
2+
3+ async function main ( ) {
4+ //Digest buffer and output digest;
5+ const data = Buffer . from ( "Helloworld" )
6+ const digested = await openssl `dgst -sha256 ${ data } ` . one ( ) ;
7+ console . log ( digested . toString ( 'utf-8' ) . split ( "=" ) [ 1 ] . trim ( ) ) //(Not ideal yet)
8+ }
9+
10+ main ( ) . catch ( console . error ) ;
Original file line number Diff line number Diff line change 1+ import { openssl } from "../src" ;
2+
3+ async function main ( ) {
4+ // Generate a 2048-bit RSA private key
5+ const key = await openssl `genpkey -algorithm RSA -outform PEM -pkeyopt rsa_keygen_bits:2048` . one ( ) ;
6+ console . log ( 'Private Key:\n' , key . data ) ;
7+ console . log ( 'SHA-256:' , key . sha256 ) ;
8+
9+ // Generate a self-signed certificate
10+ const cert = await openssl `req -x509 -new -key ${ key } -subj "/CN=localhost" -days 365 -outform PEM` . one ( ) ;
11+ console . log ( 'Certificate:\n' , cert . data ) ;
12+ console . log ( 'Is Certificate Chain?' , cert . isChain ) ;
13+ }
14+
15+ main ( ) . catch ( console . error ) ;
Original file line number Diff line number Diff line change 1+ import { openssl } from "../src" ;
2+
3+ console . log ( openssl . version )
Original file line number Diff line number Diff line change 1818 "dev" : " vite" ,
1919 "build" : " tsc && vite build" ,
2020 "preview" : " vite preview" ,
21- "test" : " vitest"
21+ "test" : " vitest" ,
22+ "example::server-cert" : " tsx examples/server-cert.ts" ,
23+ "example::version" : " tsx examples/version" ,
24+ "example::digest-sha256" : " tsx examples/digest-sha256"
2225 },
2326 "repository" : {
2427 "type" : " git" ,
2528 "url" : " git+https://github.com/SourceRegistry/node-openssl.git"
2629 },
27- "keywords" : [],
30+ "keywords" : [
31+ " openssl" ,
32+ " ssl" ,
33+ " cert" ,
34+ " pem" ,
35+ " key" ,
36+ " privatekey" ,
37+ " publickey" ,
38+ " certificate" ,
39+ " certificates" ,
40+ " chain" ,
41+ " https"
42+ ],
2843 "author" : " A.P.A. Slaa (a.p.a.slaa@projectsource.nl)" ,
29- "license" : " ISC " ,
44+ "license" : " Apache-2.0 " ,
3045 "type" : " module" ,
3146 "bugs" : {
3247 "url" : " https://github.com/SourceRegistry/node-openssl/issues"
4156 "vite" : " ^7.1.3" ,
4257 "vite-plugin-dts" : " ^4.5.4" ,
4358 "vitest" : " ^3.2.4" ,
59+ "tsx" : " ^4.20.4" ,
4460 "@semantic-release/commit-analyzer" : " ^13.0.1" ,
4561 "@semantic-release/release-notes-generator" : " ^14.0.3" ,
4662 "@semantic-release/changelog" : " ^6.0.3" ,
You can’t perform that action at this time.
0 commit comments