webcrypto-api

How to use the Web Crypto API to decrypt a file created with OpenSSL?

大憨熊 提交于 2019-12-10 05:08:48
问题 I am trying to decrypt a file that was created using the OpenSSL command-line interface. This file was created with: openssl aes-256-cbc -a -in file.txt -out file_encrypted.txt And can be decrypted with: openssl aes-256-cbc -d -a -in file_encrypted.txt By using the -p flag I can retrieve the actual value, salt and IV which will be required by the WebCrypto API: > openssl aes-256-cbc -d -a -p -in file_encrypted.txt salt=F57F1CC0CD384326 key

Generate RSA key pair using WebCrypto API and protect it with passphrase

ε祈祈猫儿з 提交于 2019-12-06 11:09:08
问题 title says it all. I was wondering how do I generate RSA key pair using WebCrypto API and how do I secure it with a passphrase so I can store it in a database. 回答1: You can generate an RSA key pair with WebCrypto and export it as jwk (Json Web Key), pkcs#8 (private) or spki (public). See SubtleCrypto.exportKey() and the example code bellow To export the key to an external system in a protected way you could use an standard like: PKCS#8: The PKCS#8 private key format defined at IETF Public Key

How to use the Web Crypto API to decrypt a file created with OpenSSL?

雨燕双飞 提交于 2019-12-05 10:33:29
I am trying to decrypt a file that was created using the OpenSSL command-line interface. This file was created with: openssl aes-256-cbc -a -in file.txt -out file_encrypted.txt And can be decrypted with: openssl aes-256-cbc -d -a -in file_encrypted.txt By using the -p flag I can retrieve the actual value, salt and IV which will be required by the WebCrypto API: > openssl aes-256-cbc -d -a -p -in file_encrypted.txt salt=F57F1CC0CD384326 key=0E971326890959386F1CFB91F185CFE109203DCEBC81DCAD4EE642F34C538E5B iv=A884549B66400EB198879F8A09148D4E secret text My current attempt looks like this:

Generate RSA key pair using WebCrypto API and protect it with passphrase

不问归期 提交于 2019-12-04 15:33:05
title says it all. I was wondering how do I generate RSA key pair using WebCrypto API and how do I secure it with a passphrase so I can store it in a database. You can generate an RSA key pair with WebCrypto and export it as jwk (Json Web Key), pkcs#8 (private) or spki (public). See SubtleCrypto.exportKey() and the example code bellow To export the key to an external system in a protected way you could use an standard like: PKCS#8: The PKCS#8 private key format defined at IETF Public Key-Cryptographic Standard Encryption #8. allow encryption with a passphrase, but WebCryptography exportKey

How to decrypt data from the result of an IE 11 encrypt operation using AES-GCM

自作多情 提交于 2019-12-04 08:12:36
I've managed to encrypt some data with AES-GCM using IE 11 on Windows 10 but I can't get decryption to work. Example encryption JS code: let plainText = new Uint8Array([1]); let key; let keyBuf = window.msCrypto.getRandomValues(new Uint8Array(32)); let iv = window.msCrypto.getRandomValues(new Uint8Array(12)); let additionalData = window.msCrypto.getRandomValues(new Uint8Array(16)); let encResult; let importOp = window.msCrypto.subtle.importKey('raw', keyBuf, { name: 'AES-GCM' }, false, ['encrypt', 'decrypt']); importOp.oncomplete = function(e) { key = e.target.result; let encryptOp = window

How can I import an RSA private key in PEM format for use with WebCrypto?

空扰寡人 提交于 2019-12-04 05:26:07
问题 I'm trying to use WebCrypto to sign a token with RSA-PSS, but I keep getting the error: DataError: Data provided to an operation does not meet requirements at crypto.subtle.importKey . This is my JavaScript code: function signToken(token, key) { crypto.subtle.importKey( 'pkcs8', PEM2Binary(key), { name: 'RSA-PSS', hash: { name: 'SHA-256' }, }, false, ['sign'] ).then(function(privKey){ crypto.subtle.sign( 'RSA-PSS', privKey, new TextEncoder().encode(token) ).then(function(signedToken){ msg =

CryptoKey ArrayBuffer to base64 and Back

给你一囗甜甜゛ 提交于 2019-12-01 08:26:30
I was wondering how do I solve this problem. I generate RSA-OAEP keypair using WebCrypto API, then I export private key in pkcs8 from the keypair which exports as ArrayBuffer and I want to encode this ArrayBuffer into base64 so I can store it as a PEM. In this testing example I am exporting key as pkcs8 and importing this pkcs8 back to CryptoKey. The problem is that sometimes it works and sometimes it does not. These are results of the code: NOTE: Only happens one of these states not all at once. NOTE2: This example does not contain -----BEGIN PRIVATE KEY----- prefix and suffix I am only

Public key encryption in Internet Explorer 11

早过忘川 提交于 2019-12-01 07:39:24
问题 I am trying to implement public key encryption using JavaScript for IE11 with the following code: <script> var data = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); var crypto = window.crypto || window.msCrypto; var cryptoSubtle = crypto.subtle; var genOp = cryptoSubtle.generateKey( { name: "RSA-OAEP", modulusLength: 2048, publicExponent: new Uint8Array([0x01, 0x00, 0x01]), hash: { name: "SHA-256" }, }, true, ["encrypt", "decrypt"] ); genOp.onerror = function (e) { console.error(e); }; genOp

CryptoKey ArrayBuffer to base64 and Back

心不动则不痛 提交于 2019-12-01 07:15:21
问题 I was wondering how do I solve this problem. I generate RSA-OAEP keypair using WebCrypto API, then I export private key in pkcs8 from the keypair which exports as ArrayBuffer and I want to encode this ArrayBuffer into base64 so I can store it as a PEM. In this testing example I am exporting key as pkcs8 and importing this pkcs8 back to CryptoKey. The problem is that sometimes it works and sometimes it does not. These are results of the code: NOTE: Only happens one of these states not all at

Digital signature from electronic smartcard in Chrome

家住魔仙堡 提交于 2019-11-30 05:01:06
For an electronic prescription system, that runs on the browser and that requieres personal signature by the professional, we are using a Java applet to sign the XML request, that then is sended to a WS, using a smartcard. But since version 42, Chrome is disabling by default NPAPI support , and in future versions next to September 2015 it will be completely disabled and then applets won't be usable at all. At Chrome NPAPI deprecation page points to WebCrypto and TLS as alternatives. But it seems that WebCrypto has leaved out of scope the support of smartcards , and it seems that TLS is only