{"action":"created","issue":{"url":"https://api.github.com/repos/diafygi/webcrypto-examples/issues/8","repository_url":"https://api.github.com/repos/diafygi/webcrypto-examples","labels_url":"https://api.github.com/repos/diafygi/webcrypto-examples/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/diafygi/webcrypto-examples/issues/8/comments","events_url":"https://api.github.com/repos/diafygi/webcrypto-examples/issues/8/events","html_url":"https://github.com/diafygi/webcrypto-examples/issues/8","id":78445623,"node_id":"MDU6SXNzdWU3ODQ0NTYyMw==","number":8,"title":"Encrypt / Decrypt a string?","user":{"login":"coolaj86","id":122831,"node_id":"MDQ6VXNlcjEyMjgzMQ==","avatar_url":"https://avatars3.githubusercontent.com/u/122831?v=4","gravatar_id":"","url":"https://api.github.com/users/coolaj86","html_url":"https://github.com/coolaj86","followers_url":"https://api.github.com/users/coolaj86/followers","following_url":"https://api.github.com/users/coolaj86/following{/other_user}","gists_url":"https://api.github.com/users/coolaj86/gists{/gist_id}","starred_url":"https://api.github.com/users/coolaj86/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coolaj86/subscriptions","organizations_url":"https://api.github.com/users/coolaj86/orgs","repos_url":"https://api.github.com/users/coolaj86/repos","events_url":"https://api.github.com/users/coolaj86/events{/privacy}","received_events_url":"https://api.github.com/users/coolaj86/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2015-05-20T09:20:52Z","updated_at":"2018-07-14T06:08:51Z","closed_at":"2015-05-21T06:01:11Z","author_association":"NONE","body":"I'm working on an example of my own, but I'm having some trouble.\n(my example: http://coolaj86.github.io/web-crypto-utahjs-preso)\n\nI found a bit of code to convert back and forth between utf8 and TypedArrays and that seems to be working just fine.\n(unibable: https://github.com/coolaj86/unibabel-js)\n\nHowever, the \"encrypted\" buffer isn't the length I would expect and it can't be decrypted.\n\nI think I'm missing something. To you see anything out of order here?\n\n``` javascript\n'use strict';\n\nvar webcrypto = window.crypto || window.msCrypto || window.webkitCrypto || window.mozCrypto;\n\nvar keyStr = 'VzC2coGPrvecrigzB38DRLGiwVrgiwnQznyrD9BYxAk=';\nvar keyBuf = window.Unibabel.base64ToArr(keyStr);\nvar message = \"this is a secret message\";\nvar ivLen = (128 / 8);\nvar iv = new Uint8Array(ivLen); // defaults to zero\nvar arrb = window.Unibabel.strToUtf8Arr(message);\nvar data = arrb.buffer;\nconsole.log('message as buffer', arrb.length);\nconsole.log(arrb);\n\nconsole.log('keyBuf', keyBuf.length);\nconsole.log(keyBuf);\n\nwebcrypto.subtle.importKey(\n    \"raw\",\n    keyBuf,\n    { name: \"AES-CBC\" },\n    true,\n    [\"encrypt\", \"decrypt\"]\n)\n.then(function(key){\n    //returns the symmetric key\n    console.log('key', key);\n\n    return window.crypto.subtle.encrypt(\n        { name: \"AES-CBC\", iv: iv },\n        key, //from generateKey or importKey above\n        data //ArrayBuffer of data you want to encrypt\n    ).then(function(encrypted){\n      //returns an ArrayBuffer containing the encrypted data\n      // TODO base64\n      //console.log(new Uint8Array(encrypted));\n      console.log('encrypted');\n      console.log(new Uint8Array(encrypted));\n      console.log(new Uint8Array(encrypted).length);\n\n      console.log('encrypted', window.Unibabel.arrToBase64(new Uint8Array(encrypted)));\n\n      window.crypto.subtle.decrypt(\n          { name: \"AES-CBC\", iv: iv },\n          key, //from generateKey or importKey above\n          data //ArrayBuffer of data you want to encrypt\n      )\n      .then(function(decrypted){\n          //returns an ArrayBuffer containing the encrypted data\n          console.log(new Uint8Array(encrypted));\n          console.log('decrypted', window.Unibabel.arrToBase64(new Uint8Array(decrypted)));\n      })\n\n\n\n\n\n\n       // error handling\n\n      .catch(function(err){\n          console.error(err);\n      });\n    })\n    .catch(function(err){\n        console.error(err);\n    });\n})\n.catch(function(err){\n    console.error(err);\n});\n```\n"},"comment":{"url":"https://api.github.com/repos/diafygi/webcrypto-examples/issues/comments/405001942","html_url":"https://github.com/diafygi/webcrypto-examples/issues/8#issuecomment-405001942","issue_url":"https://api.github.com/repos/diafygi/webcrypto-examples/issues/8","id":405001942,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNTAwMTk0Mg==","user":{"login":"Ruffio","id":1877612,"node_id":"MDQ6VXNlcjE4Nzc2MTI=","avatar_url":"https://avatars0.githubusercontent.com/u/1877612?v=4","gravatar_id":"","url":"https://api.github.com/users/Ruffio","html_url":"https://github.com/Ruffio","followers_url":"https://api.github.com/users/Ruffio/followers","following_url":"https://api.github.com/users/Ruffio/following{/other_user}","gists_url":"https://api.github.com/users/Ruffio/gists{/gist_id}","starred_url":"https://api.github.com/users/Ruffio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ruffio/subscriptions","organizations_url":"https://api.github.com/users/Ruffio/orgs","repos_url":"https://api.github.com/users/Ruffio/repos","events_url":"https://api.github.com/users/Ruffio/events{/privacy}","received_events_url":"https://api.github.com/users/Ruffio/received_events","type":"User","site_admin":false},"created_at":"2018-07-14T06:08:51Z","updated_at":"2018-07-14T06:08:51Z","author_association":"NONE","body":"@mnjsnj and you have remembered to download the unibabel? That lib isn't native..."}}
{"actor":{"display_login":"Ruffio"}}