This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Arguments: None | |
* | |
* Returns: Promise resolving to: | |
* { | |
* privateKey: CryptoKey, | |
* publicKey: CryptoKey, | |
* } | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://github.com/diafygi/webcrypto-examples | |
window.crypto.subtle.encrypt( | |
{ | |
name: "AES-GCM", | |
//Don't re-use initialization vectors! | |
//Always generate a new iv every time your encrypt! | |
//Recommended to use 12 bytes length | |
iv: window.crypto.getRandomValues(new Uint8Array(12)), |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var forEach = require("lodash.foreach"); | |
var chai = require("chai"); | |
var JWE = require("../../lib/jwe"), | |
JWK = require("../../lib/jwk"); | |
var assert = chai.assert; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package gist; | |
import java.math.BigInteger; | |
import java.security.SecureRandom; | |
public class MSDBRG { | |
private static BigInteger TWO = new BigInteger("2"); | |
public static void main(String[] args) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package orig; | |
import java.math.BigInteger; | |
import java.security.InvalidKeyException; | |
import java.security.KeyFactory; | |
import java.security.NoSuchAlgorithmException; | |
import java.security.PrivateKey; | |
import java.security.PublicKey; | |
import java.security.spec.ECFieldFp; | |
import java.security.spec.ECParameterSpec; | |
import java.security.spec.ECPoint; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.math.BigInteger; | |
import java.security.InvalidKeyException; | |
import java.security.KeyFactory; | |
import java.security.NoSuchAlgorithmException; | |
import java.security.PrivateKey; | |
import java.security.PublicKey; | |
import java.security.spec.ECFieldFp; | |
import java.security.spec.ECParameterSpec; | |
import java.security.spec.ECPoint; | |
import java.security.spec.ECPrivateKeySpec; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static ECKey generateECJWK(final ECKey.Curve curve) | |
throws Exception { | |
final ECParameterSpec ecParameterSpec = curve.toECParameterSpec(); | |
KeyPairGenerator generator = KeyPairGenerator.getInstance("EC"); | |
generator.initialize(ecParameterSpec); | |
KeyPair keyPair = generator.generateKeyPair(); | |
final ECPrivateKey privateKey = (ECPrivateKey) keyPair.getPrivate(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void testRecoverPrivateReceiverKey() throws JoseException { | |
String alg = "ECDH-ES+A128KW"; | |
String enc = "A128CBC-HS256"; | |
JsonWebEncryption jwe = new JsonWebEncryption(); | |
String receiverJwkJson = "\n{\"kty\":\"EC\",\n" + | |
" \"crv\":\"P-256\",\n" + | |
" \"x\":\"weNJy2HscCSM6AEDTDg04biOvhFhyyWvOHQfeF_PxMQ\",\n" + | |
" \"y\":\"e8lnCO-AlStT-NJVX-crhB7QRYhiix03illJOVAOyck\",\n" + | |
" \"d\":\"VEmDZpDXXK8p8N0Cndsxs924q6nS1RXFASRl6BfUqdw\"\n" + |