If you don't run your website on SSL
with https
the answer is: You can't use window.crypto.subtle
. You have to configure SSL
for your webserver. Look in MDN docs about Crypto.subtle it has a big warning on top op the page saying Secure context which means it is only available on https
.
BUT there is an alternative solution if you still need a support for http
only. And it does not involve using window.crypto.subtle
but other open-source third party library instead. Here is how:
You can use Forge which is a crypto library that has same functionality like window.crypto.sybtle
It has all crypto algorithms for your needs.
You can use forge instead of window.crypto
when you run your services over http
.
Be aware that APIs are very different and you need to write different code for cryptography using forge
than using window.crypto
.
You need to read forge docs to make specific cryptography method work for your use case.
You CAN NOT use same code that works in window.crypto.subtle when using forge you need to find your own way how to use forge for encryption.
For your reference to see how forge
vs window.crypto.subtle
codes are different read below.
Links to original window.crypto.subtle
based darkwire.io code and translated darkwire.io code that is using forge
instead of window.crypto.subtle
:
original code using window.crypto.subtle
:
here
code translated to use forge, can run on http
without SSL
:
here
I had translated darkwire.io to use forge for my own project that runs on http
and needs encrypted communication method between clients.