Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const fn = async (dispatch, getState) => {
const offlineResources = getOfflineResources(getState())
// generate a random ID to identify this resource
const id = forge.util.bytesToHex(forge.random.getBytes(4))
if (offlineResources[id] != null) {
return dispatch({
type: types.OFFLINE_RESOURCE_ALREADY_EXISTS,
id,
name
})
}
// MapboxGL expects these as [[maxX, maxY], [minX, minY]]
const bounds = [[aoi[2], aoi[3]], [aoi[0], aoi[1]]]
dispatch({
type: types.FETCHING_OFFLINE_RESOURCES,
id,
name,
function decryptMessage (key_hex, msg) {
let key = forge.util.hexToBytes (key_hex);
let msg_buf = Buffer.from (msg, 'hex');
let iv = forge.util.createBuffer (msg_buf.slice (-12).toString ('binary'));
let tag = forge.util.createBuffer (msg_buf.slice (-28, -12).toString ('binary'));
const decipher = forge.cipher.createDecipher ('AES-GCM', key);
decipher.start ({ iv: iv, tag: tag });
decipher.update (forge.util.createBuffer (msg_buf.slice (0, -28).toString ('binary')));
if (decipher.finish ()) {
return decipher.output.getBytes ();
}
}
async decrypt(cipherString: CipherString, key?: SymmetricCryptoKey,
outputEncoding: string = 'utf8'): Promise {
const ivBytes: string = forge.util.decode64(cipherString.initializationVector);
const ctBytes: string = forge.util.decode64(cipherString.cipherText);
const macBytes: string = cipherString.mac ? forge.util.decode64(cipherString.mac) : null;
const decipher = await this.aesDecrypt(cipherString.encryptionType, ctBytes, ivBytes, macBytes, key);
if (!decipher) {
return null;
}
if (outputEncoding === 'utf8') {
return decipher.output.toString('utf8');
} else {
return decipher.output.getBytes();
}
}
function _rsaEncrypt( byteString, publicKey ) {
const encrypted = publicKey.encrypt( byteString, ASYMMETRIC_ALGORITHM, ASYMMETRIC_OPTIONS );
return forge.util.encode64( encrypted );
}
publicKey,
jwksOrigin,
}: {
privateKey: forge.pki.PrivateKey
publicKey: forge.pki.PublicKey
jwksOrigin?: string
}): JWKS => {
const helperKey = new NodeRSA()
helperKey.importKey(forge.pki.privateKeyToPem(privateKey))
const { n: modulus, e: exponent } = helperKey.exportKey('components')
const certPem = createCertificate({
jwksOrigin,
privateKey,
publicKey,
})
const certDer = forge.util.encode64(
forge.asn1
.toDer(forge.pki.certificateToAsn1(forge.pki.certificateFromPem(certPem)))
.getBytes()
)
const thumbprint = base64url.encode(getCertThumbprint(certDer))
return {
keys: [
{
alg: 'RSA256',
e: String(exponent),
kid: thumbprint,
kty: 'RSA',
n: modulus.toString('base64'),
use: 'sig',
x5c: [certDer],
x5t: thumbprint,
label: sessionId
});
let time = new Uint64LE(moment.utc().unix());
time = [...time.toBuffer()].reverse();
iterator = new Uint64LE(iterator);
iterator = [...iterator.toBuffer()].reverse();
pin = Buffer.from(pin, 'utf8');
let buf = Buffer.concat([pin, Buffer.from(time), Buffer.from(iterator)]);
let padding = blockSize - buf.length % blockSize;
let paddingArray = [];
for (let i=0; i
encryptStringWithBase64(string) {
return forge.util.encode64(string)
},