Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function testEncryptVector ({ name, keysInfo, encryptOp, plainTextData }: EncryptTestVectorInfo, decryptOracle: URL): Promise {
try {
const cmm = encryptMaterialsManagerNode(keysInfo)
const { result: encryptResult } = await encrypt(cmm, plainTextData, encryptOp)
const decryptResponse = await got.post(decryptOracle, {
headers: {
'Content-Type': 'application/octet-stream',
'Accept': 'application/octet-stream'
},
body: encryptResult,
encoding: null
})
needs(decryptResponse.statusCode === 200, 'decrypt failure')
const { body } = decryptResponse
const result = plainTextData.equals(body)
return { result, name }
} catch (err) {
return { result: false, name, err }
}
}
export function rsaPadding (keyInfo: RsaKeyInfo) {
const paddingAlgorithm = keyInfo['padding-algorithm']
const paddingHash = keyInfo['padding-hash']
if (paddingAlgorithm === 'pkcs1') return constants.RSA_PKCS1_PADDING
needs(paddingHash === 'sha1', 'Not supported at this time.')
return constants.RSA_PKCS1_OAEP_PADDING
}