Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                // (base: https://qiita.com/tomoyukilabs/items/eac94fdb2d0ca92f443a)
async function keygenAndEncryptAndDecrypt() {
   const aKeyPair = await window.crypto.subtle.generateKey(
     { name: 'ECDH', namedCurve: 'P-256'},
     false,
     ['deriveKey', 'deriveBits']
   );
   const aPublicKeyJWK = await crypto.subtle.exportKey('jwk', aKeyPair.publicKey);
 
   const bKeyPair = await window.crypto.subtle.generateKey(
     { name: 'ECDH', namedCurve: 'P-256'},
     false,
     ['deriveKey', 'deriveBits']
   );
   const bPublicKeyJWK = await crypto.subtle.exportKey('jwk', bKeyPair.publicKey);
 
   const bRemotePublicKey = await crypto.subtle.importKey(
     'jwk',
     bPublicKeyJWK,
     {name: 'ECDH', namedCurve: 'P-256'},
     false,
     []
   );
 
   const iv = crypto.getRandomValues(new Uint8Array(12));
   const aKey = await crypto.subtle.deriveKey(
     { name: 'ECDH', public: bRemotePublicKey },
     aKeyPair.privateKey,
     {'name': 'AES-GCM', length: 128},
     false,
     ['encrypt', 'decrypt']
   );
 
   const raw = new Uint8Array([1, 2, 3]);
   const encrypted = await crypto.subtle.encrypt(
     { name: 'AES-GCM', iv, tagLength: 128 },
     aKey,
     raw
   );
 
   const aRemotePublicKey = await crypto.subtle.importKey(
     'jwk',
     aPublicKeyJWK,
     { name: 'ECDH', namedCurve: 'P-256'},
     false,
     []
   );
 
   const bKey = await crypto.subtle.deriveKey(
     { name: 'ECDH', public: aRemotePublicKey },
     bKeyPair.privateKey,
     { name: 'AES-GCM', length: 128 },
     false,
     ['encrypt', 'decrypt']
   );
 
   const decrypted = await crypto.subtle.decrypt(
     { name: 'AES-GCM', iv, tagLength: 128 },
     bKey,
     encrypted
   );
 
  // Whether raw and decrypted are the same
  return JSON.stringify([...raw]) == JSON.stringify([...new Uint8Array(decrypted)]);
}

(async () => {
  const startDate = new Date();
  for(let i = 0; i < 100; i++) {
    const b = await keygenAndEncryptAndDecrypt();
    console.log(b);
  }
  console.log('diff millis: ', new Date() - startDate);
})();


              
            
!
999px

Console