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

Method encrypt

packages/core/wgc/crypto/SubtleCrypto.ts:259–303  ·  view source on GitHub ↗
(algorithm: RsaOaepParams, key: CryptoKey, data: TypedArray | ArrayBuffer)

Source from the content-addressed store, hash-verified

257 }
258
259 encrypt(algorithm: RsaOaepParams, key: CryptoKey, data: TypedArray | ArrayBuffer) {
260 return new Promise((resolve, reject) => {
261 let error: Error;
262 switch (algorithm?.name) {
263 case 'RSA-OAEP':
264 {
265 try {
266 if (__IOS__) {
267 const hash = parseHash(key.algorithm.hash.name);
268 const d = NSData.dataWithData(data as never);
269
270 NSCCrypto.encryptRsaKeyHashDataCompletion(key.type === 'private', key[parent_], hash, d, (ret, error) => {
271 if (ret) {
272 resolve(interop.bufferFromData(ret));
273 } else {
274 reject(new Error('Failed to encrypt data'));
275 }
276 });
277 }
278
279 if (__ANDROID__) {
280 const hash = parseHash(key.algorithm.hash.name);
281 const ret = (<any>org).nativescript.winter_tc.Crypto.encryptRsaOAEP(key[parent_], hash, data);
282 if (ret) {
283 resolve((<any>ArrayBuffer).from(ret));
284 } else {
285 reject(new Error('Failed to encrypt data'));
286 }
287 }
288 } catch (error) {
289 reject(error);
290 }
291 }
292 break;
293 default:
294 error = new Error('Operation is not supported');
295 break;
296 }
297
298 if (error) {
299 reject(error);
300 return;
301 }
302 });
303 }
304
305 decrypt(algorithm: RsaOaepParams, key: CryptoKey, data: TypedArray | ArrayBuffer) {
306 return new Promise((resolve, reject) => {

Callers 1

gen_rsa_oaepFunction · 0.80

Calls 3

parseHashFunction · 0.85
encryptRsaOAEPMethod · 0.80
resolveFunction · 0.50

Tested by

no test coverage detected