{"library":"msrcrypto","title":"MSR JavaScript Cryptography Library","description":"msrCrypto is a JavaScript cryptography library, originally developed by Microsoft Research and subsequently maintained by Kevlened. It serves as a polyfill for the W3C Web Cryptography API, enabling modern cryptographic primitives like RSA-OAEP, AES-CBC, SHA-256/384/512, HMAC, ECDH, and ECDSA in environments where native Web Crypto API support is absent or inconsistent. Its primary differentiation is its broad browser compatibility, extending to older browsers like Internet Explorer 8, 9, 10, and 11, alongside modern browsers. Since version 1.4, it has adopted a Promise-based API for asynchronous operations, aligning with the Web Crypto API specification. The current stable version, as per the user's input, is 1.5.8, though a `1.6.5` version appears on npm under `@dashdot/msrcrypto` with the last publish 4 years ago, and `1.5.8` itself was published 6 years ago. Its release cadence appears infrequent, with updates primarily addressing API compliance, security bug fixes, and feature enhancements for specific algorithms.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install msrcrypto"],"cli":null},"imports":["<script src=\"path/to/msrcrypto.js\"></script>","msrCrypto.subtle.encrypt(...)","if (window.msrCrypto && typeof window.msrCrypto.initPrng === 'function') {\n  // Obtain 48 random bytes from a secure source (e.g., server-side)\n  const entropy = new Uint8Array(48);\n  // Populate entropy with cryptographically strong random values\n  // For example, if on Node.js: require('crypto').randomBytes(48);\n  // For modern browser: window.crypto.getRandomValues(entropy);\n  window.msrCrypto.initPrng(entropy);\n}"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"// This quickstart assumes msrcrypto.js has been loaded via a <script> tag,\n// making the global `msrCrypto` object available.\n\n// 1. Generate an AES-CBC key\nconst iv = new new Uint8Array(16); // Initialization Vector\n// On modern browsers, use window.crypto.getRandomValues(iv);\n// On older browsers, ensure PRNG is seeded (see warnings) or provide secure random bytes\n// For this example, we'll simulate random values or assume a modern environment fallback\n// For a truly secure setup in older IE, you'd need server-side entropy for msrCrypto.initPrng()\n\n// Simulate getRandomValues for environments where it might not be available or fully polyfilled for iv generation\nif (typeof window.crypto !== 'undefined' && typeof window.crypto.getRandomValues === 'function') {\n  window.crypto.getRandomValues(iv);\n} else {\n  // Fallback for demonstration, NOT cryptographically secure in production for IV\n  for (let i = 0; i < iv.length; i++) iv[i] = Math.floor(Math.random() * 256);\n}\n\nmsrCrypto.subtle.generateKey(\n  {\n    name: \"AES-CBC\",\n    length: 256, // For AES-256\n  },\n  true, // key is extractable\n  [\"encrypt\", \"decrypt\"]\n)\n.then(function(key) {\n  console.log(\"AES-CBC Key generated successfully.\");\n  // 2. Encrypt some data\n  const dataToEncrypt = new TextEncoder().encode(\"Hello, msrcrypto, this is a secret message!\");\n\n  return msrCrypto.subtle.encrypt(\n    {\n      name: \"AES-CBC\",\n      iv: iv,\n    },\n    key,\n    dataToEncrypt\n  );\n})\n.then(function(encryptedData) {\n  console.log(\"Data encrypted successfully (ArrayBuffer):\");\n  // In IE8/9, this might be a regular Array, convert for consistent logging if needed\n  console.log(new Uint8Array(encryptedData));\n  // Further steps would involve decrypting or sending the data\n})\n.catch(function(error) {\n  console.error(\"Encryption failed:\", error);\n});","lang":"javascript","description":"This quickstart demonstrates how to generate an AES-CBC key and encrypt a plain text message using the `msrCrypto.subtle` API, mimicking the Web Crypto API. It highlights the promise-based asynchronous operations.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}