MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / gen_rsa_oaep

Function gen_rsa_oaep

apps/toolbox/src/pages/winter-tc.ts:69–108  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

67}
68
69async function gen_rsa_oaep() {
70 let message = 'Hello World';
71 let enc = new TextEncoder();
72 const encoded = enc.encode(message);
73
74 const kp = await crypto.subtle.generateKey(
75 {
76 name: 'RSA-OAEP',
77 modulusLength: 4096,
78 publicExponent: new Uint8Array([1, 0, 1]),
79 hash: 'SHA-256',
80 },
81 true,
82 ['encrypt', 'decrypt'],
83 );
84
85 try {
86 const ciphertext = await crypto.subtle.encrypt(
87 {
88 name: 'RSA-OAEP',
89 },
90 kp.publicKey,
91 encoded,
92 );
93 let decrypted = await crypto.subtle.decrypt(
94 {
95 name: 'RSA-OAEP',
96 },
97 kp.privateKey,
98 ciphertext,
99 );
100
101 let dec = new TextDecoder();
102 const decryptedValue = dec.decode(decrypted);
103
104 console.log('decryptedValue', decryptedValue, decryptedValue === message);
105 } catch (error) {
106 console.log('gen: error', error);
107 }
108}

Callers 1

runFunction · 0.85

Calls 6

encodeMethod · 0.95
decodeMethod · 0.95
generateKeyMethod · 0.80
encryptMethod · 0.80
decryptMethod · 0.80
logMethod · 0.45

Tested by

no test coverage detected