2

I have created public and private key using SubtleCrypto api. I am using webcrypto-shim to overcome some of the unimplemented methods of subtle in Safari. I am able to generate a keypair and sign my data with it.

Then I try to save my keypair on IndexedDB, it appears that my save transactions succeeded, no errors there. But when I want to use the public key again for signing, First I retrieve it from the IndexedDB and then I use SubtleCrypto.exportKey() but it fails with an error

TypeError: Type error

I am trying to make it work on Safari desktop 9.1.2, I am also using IndexedDBShim

I suspect that the saving doesn't really work and my keys aren't being stored properly on IndexedDB. On the save transaction I save the keys without exporting them, meaning I am saving the object that I receviced from SubtleCrypto.generateKey().

Another thing is that the same code works on Chrome.

Yuri N
  • 76
  • 4
  • 1
    Have you set the key as exportable? Are you using `jwk` to export the key? WebCrypto in WebKit does not support spki/pkcs8 formats. https://bugs.webkit.org/show_bug.cgi?id=129978 – pedrofb Aug 22 '16 at 08:57
  • Yes, I was using exportable and `jwk`. I finally was able to save my keys. I did it by first exporting it to `jwk` and then saving the result and not the CryptoKey object itself. – Yuri N Aug 22 '16 at 13:11
  • If you're talking about your code and presenting an error from your code, then please show your code. If you solved it, you can answer your own question. – Artjom B. Aug 22 '16 at 17:45
  • FWIW, IndexedDB can only store objects clonable by the Structured Cloning Algorithm. CryptoKey should be clonable by the algorithm per https://www.w3.org/TR/WebCryptoAPI/#cryptokey-interface-clone , but the typeson-registry on which IndexedDBShim depends does not yet support serializing/deserializing this type of object (assuming JavaScript exposes on its APIs the equivalent of the internal slots). Once it may, we should be able to update IndexedDBShim to use the updated typeson-registry so such objects can be cloned directly. – Brett Zamir Jun 22 '17 at 06:40

0 Answers0