Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use SubtleCrypto in chrome (window.crypto.subtle is undefined)

This is really embarassing

on virtually any site on the internet,

window.crypto.subtle 

returns

SubtleCrypto {}   __proto__: SubtleCrypto 

in the chrome console (v61 (Official Build) (64-bit))

except for

my webpage, and blank.org

where

window.crypto.subtle 

returns

undefined 

according to https://developer.mozilla.org/en-US/docs/Web/API/Crypto/subtle it's a read-only property that should always return a SubtleCrypto object.

what could I have done, or what has blank.org done that it could possibly not?

ps: in firefox it seems to work as intended on both my site and blank.org

like image 821
guest Avatar asked Sep 28 '17 11:09

guest


People also ask

What is window crypto subtle?

subtle. Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers. The Crypto. subtle read-only property returns a SubtleCrypto which can then be used to perform low-level cryptographic operations.

What does crypto subtle Digest mean?

The digest() method of the SubtleCrypto interface generates a digest of the given data. A digest is a short fixed-length value derived from some variable-length input. Cryptographic digests should exhibit collision-resistance, meaning that it's hard to come up with two different inputs that have the same digest value.

What is window Crypto?

The window. crypto property returns a Crypto object which is associated with the global object. This object allows web pages to run various cryptographic operations on the browser side. It has one property, which is the subtle property.


2 Answers

According to the spec (via Github issues) a la this Google page for WebCrypto:

crypto.subtle is supposed to be undefined in insecure contexts

like image 179
Zmart Avatar answered Oct 15 '22 00:10

Zmart


check your URL's

if it is https://localhost:PORT or 0.0.0.0:port or 127.0.0.0:port

change it to proper hostname URL something like http://localhost:PORT

worked for me! Thanks @Zmart

like image 32
Rohit Avatar answered Oct 14 '22 22:10

Rohit