index : matrix-js-sdk

My fork of matrix-js-sdk

diff options
context:
space:
mode:
-rw-r--r--src/crypto/aes.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/crypto/aes.js b/src/crypto/aes.js
index 1556413f..b9bf836d 100644
--- a/src/crypto/aes.js
+++ b/src/crypto/aes.js
@@ -23,6 +23,12 @@ const subtleCrypto = (typeof window !== "undefined" && window.crypto) ?
// salt for HKDF, with 8 bytes of zeros
const zerosalt = new Uint8Array(8);
+var nativeCrypto = null;
+
+export function setNativeCrypto(crypto) {
+ nativeCrypto = crypto;
+}
+
/**
* encrypt a string in Node.js
*
@@ -242,10 +248,16 @@ async function deriveKeysBrowser(key, name) {
}
export function encryptAES(...args) {
+ if (nativeCrypto) {
+ return nativeCrypto.encryptNative(...args);
+ }
return subtleCrypto ? encryptBrowser(...args) : encryptNode(...args);
}
export function decryptAES(...args) {
+ if (nativeCrypto) {
+ return nativeCrypto.decryptNative(...args);
+ }
return subtleCrypto ? decryptBrowser(...args) : decryptNode(...args);
}