3
Web Crypto API: Asymmetric Encryption With Passphrase?
(lemmy.world)
How would one include a passphrase when using the web crypto API when working with asymmetric encryption. I was able to figure out how to do asymmetric encryption without a passphrase using the web crypto API and was able to figure out how to do asymmetric encryption using the crypto library in NodeJS.
Asymmetric encryption using Web Crypto API (No Passphrase)
import { webcrypto } from 'crypto';
const MY_TEXT = 'My Text';
(async function () {
const { publicKey, privateKey } = await webcrypto.subtle.generateKey(
{
name: 'rsa-Oaep',
modulusLength: 2048,
publicExponent: new Uint8Array([1, 0, 1]),
hash: 'sha-256',
},
true,
['encrypt', 'decrypt']
);
const encryptedTextArrayBuffer = await webcrypto.subtle.encrypt(
{
name: 'rsa-Oaep',
},
publicKey,
new TextEncoder().encode(MY_TEXT)
);
let encryptedTextUint8Array = new Uint8Array(encryptedTextArrayBuffer);
const ENCRYPTED_TEXT = convertUint8ArrayToBase64String(encryptedTextUint8Array);
console.log(ENCRYPTED_TEXT);
encryptedTextUint8Array = convertBase64StringToUint8Array(ENCRYPTED_TEXT);
const decryptedArrayBuffer = await webcrypto.subtle.decrypt(
{
name: 'rsa-Oaep',
},
privateKey,
encryptedTextUint8Array.buffer
);
console.log(new TextDecoder().decode(decryptedArrayBuffer));
})();
function convertUint8ArrayToBase64String(uint8Array) {
const CHARACTER_CODES = String.fromCharCode(...uint8Array);
return btoa(CHARACTER_CODES);
}
function convertBase64StringToUint8Array(base64String) {
const CHARACTER_CODES = atob(base64String);
const uint8Array = new Uint8Array(CHARACTER_CODES.length);
uint8Array.set(
new Uint8Array(
[...CHARACTER_CODES].map(function (currentCharacterCode) {
return currentCharacterCode.charCodeAt(0);
})
))}
What company do you work for in XR?
I got the XReal One as a portable ergonomic monitor and I may use them as my main monitor going forward. I have a sit/stand desk with monitor arms which I can adjust the height and position for an ergonomic design to always look straight at the monitor and not looking down.
From my research currently the XReal Ones are the best AR/XR glasses on the market due to the chip built into them, not needing any other devices or software to run, just plug in play. The XReal One Pros which I think are coming out soon have some better specs but to me, not worth the extra money.
I been using them for regular desktop/laptop task and coding and I prefer to use the anchor mode when doing this. I sometimes also use the ultra-wide mode to simulate 2 monitors. I also been using them for gaming and I will either have it in follow or anchor mode but never use ultra-wide mode for gaming.