MCPcopy Create free account
hub / github.com/apache/cloudstack / encrypt

Method encrypt

systemvm/agent/noVNC/core/crypto/rsa.js:86–102  ·  view source on GitHub ↗
(_algorithm, message)

Source from the content-addressed store, hash-verified

84 }
85
86 async encrypt(_algorithm, message) {
87 if (message.length > this._keyBytes - 11) {
88 return null;
89 }
90 const ps = new Uint8Array(this._keyBytes - message.length - 3);
91 window.crypto.getRandomValues(ps);
92 for (let i = 0; i < ps.length; i++) {
93 ps[i] = Math.floor(ps[i] * 254 / 255 + 1);
94 }
95 const em = new Uint8Array(this._keyBytes);
96 em[1] = 0x02;
97 em.set(ps, 2);
98 em.set(message, ps.length + 3);
99 const emBigInt = u8ArrayToBigInt(em);
100 const c = modPow(emBigInt, this._eBigInt, this._nBigInt);
101 return bigIntToU8Array(c, this._keyBytes);
102 }
103
104 async decrypt(_algorithm, message) {
105 if (message.length !== this._keyBytes) {

Callers

nothing calls this directly

Calls 4

u8ArrayToBigIntFunction · 0.90
modPowFunction · 0.90
bigIntToU8ArrayFunction · 0.90
setMethod · 0.65

Tested by

no test coverage detected