-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated and changed some details in the code
- Loading branch information
1 parent
da858ba
commit dc5e974
Showing
8 changed files
with
223 additions
and
141 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
|
||
<link rel="stylesheet" href="./css/basic.css" /> | ||
<link rel="stylesheet" href="./css/main.css" /> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
|
||
<script src="webxdc.js"></script> | ||
</head> | ||
<body> | ||
<div id="headerDiv"> | ||
<button id="sendRequestBtn">Send request to chat</button> | ||
</div> | ||
<link rel="stylesheet" href="style.css" /> | ||
|
||
<div id="chatsDiv"></div> | ||
<script src="webxdc.js"></script> | ||
</head> | ||
|
||
<script type="module" src="./js/main.js"></script> | ||
</body> | ||
</html> | ||
<body> | ||
<div id="headerDiv" style="text-align: center;"> | ||
<button id="sendRequestBtn">Send chat request</button> | ||
</div> | ||
|
||
<div id="chatsDiv"></div> | ||
|
||
<script type="module" src="js/main.js"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,71 @@ | ||
let rsaAlgorithm = () => { | ||
return { | ||
name: "RSA-OAEP", | ||
modulusLength: 2048, | ||
publicExponent: new Uint8Array([1, 0, 1]), | ||
hash: "SHA-256", | ||
}; | ||
}; | ||
const rsaAlgorithm = { | ||
name: "RSA-OAEP", | ||
modulusLength: 2048, | ||
publicExponent: new Uint8Array([1, 0, 1]), | ||
hash: "SHA-256", | ||
} | ||
|
||
export let randomId = () => crypto.randomUUID(); | ||
export const randomId = () => crypto.randomUUID(); | ||
|
||
/** | ||
* | ||
* @returns {Promise<CryptoKeyPair>} | ||
*/ | ||
export async function createKeys() { | ||
let keys = await crypto.subtle.generateKey(rsaAlgorithm(), true, [ | ||
return await crypto.subtle.generateKey(rsaAlgorithm, true, [ | ||
"encrypt", | ||
"decrypt", | ||
]); | ||
|
||
return keys; | ||
} | ||
|
||
/** | ||
* | ||
* @param {CryptoKey} key | ||
* @returns {Promise<JsonWebKey>} | ||
*/ | ||
export async function exportKey(key) { | ||
return crypto.subtle.exportKey("jwk", key); | ||
} | ||
|
||
/** | ||
* | ||
* @param {JsonWebKey} jsonWebKey | ||
* @returns {Promise<CryptoKey>} | ||
*/ | ||
export async function importKey(jsonWebKey) { | ||
let key = await crypto.subtle.importKey( | ||
return await crypto.subtle.importKey( | ||
"jwk", | ||
jsonWebKey, | ||
rsaAlgorithm(), | ||
rsaAlgorithm, | ||
true, | ||
["encrypt"], | ||
); | ||
|
||
return key; | ||
} | ||
|
||
export async function encrypt(arrayBuffer, key) { | ||
let encryptedArrayBuffer = await crypto.subtle.encrypt( | ||
/** | ||
* | ||
* @param {ArrayBuffer} data | ||
* @param {CryptoKey} key | ||
* @returns {Promise<ArrayBuffer>} | ||
*/ | ||
export async function encrypt(data, key) { | ||
return await crypto.subtle.encrypt( | ||
{ name: "RSA-OAEP" }, | ||
key, | ||
arrayBuffer, | ||
data, | ||
); | ||
|
||
return encryptedArrayBuffer; | ||
} | ||
|
||
export async function decrypt(encryptedArrayBuffer, key) { | ||
let decryptedArrayBuffer = await crypto.subtle.decrypt( | ||
/** | ||
* | ||
* @param {ArrayBuffer} encryptedData | ||
* @param {CryptoKey} key | ||
* @returns {Promise<ArrayBuffer>} | ||
*/ | ||
export async function decrypt(encryptedData, key) { | ||
return await crypto.subtle.decrypt( | ||
{ name: "RSA-OAEP" }, | ||
key, | ||
encryptedArrayBuffer, | ||
encryptedData, | ||
); | ||
|
||
return decryptedArrayBuffer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.