Fix for Safari support using webkit prefix

This commit is contained in:
Alan Friedman 2016-01-20 17:17:31 -05:00
parent 2a8e4842c3
commit 64b12776b8
2 changed files with 7 additions and 6 deletions

View File

@ -43,7 +43,7 @@ $(function() {
if (!roomId) return;
if ((!window.crypto && !window.msCrypto) || !window.crypto.subtle) {
if (!window.crypto || (!window.crypto.subtle && !window.crypto.webkitSubtle)) {
$('#no-crypto').modal({
backdrop: 'static',
show: false,
@ -54,6 +54,7 @@ $(function() {
}
var crypto = window.crypto;
var cryptoSubtle = window.crypto.subtle || window.crypto.webkitSubtle;
let socket = io(roomId);
$('#roomIdKey').text(roomId.replace('/', ''));
@ -579,25 +580,25 @@ $(function() {
}
function createKey(password) {
return crypto.subtle.digest({
return cryptoSubtle.digest({
name: "SHA-256"
}, convertStringToArrayBufferView(password))
.then(function(result) {
return window.crypto.subtle.importKey("raw", result, {
return cryptoSubtle.importKey("raw", result, {
name: "AES-CBC"
}, false, ["encrypt", "decrypt"]);
});
}
function encryptData(data, key, vector) {
return crypto.subtle.encrypt({
return cryptoSubtle.encrypt({
name: "AES-CBC",
iv: vector
}, key, convertStringToArrayBufferView(data));
}
function decryptData(data, key, vector) {
return crypto.subtle.decrypt({
return cryptoSubtle.decrypt({
name: "AES-CBC",
iv: vector
}, key, data);

View File

@ -188,7 +188,7 @@
</div>
<div class="modal-body">
<p>Your browser does not support the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Crypto" target="_blank">Crypto Web API</a>.</p>
<p>Try using the lastest version of Chrome or Firefox.</p>
<p>Try using the lastest version of Chrome, Firefox or Safari.</p>
</div>
</div>
</div>