-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtestHE.js
More file actions
57 lines (44 loc) · 1.56 KB
/
testHE.js
File metadata and controls
57 lines (44 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Homomorphic Encryption Test Example
const ChainsqlAPI = require('../src/index');
main()
async function main(){
const c = new ChainsqlAPI();
try{
var encyptParms = {
schemeType : 'ckks',
polyModulusDegree : 2048
}
var heKeypair = await c.genHomEncryptKeypair(encyptParms)
var encyptParams = {
homEncryptParams:heKeypair.homEncryptParams,
homPublicKey:heKeypair.homPublicKey,
homPlainValue:'121.00001'
}
var encryptCipher = await c.homEncrypt(encyptParams)
var decryptParams = {
homEncryptParams:heKeypair.homEncryptParams,
homPrivateKey:heKeypair.homPrivateKey,
homCipherText:encryptCipher
}
var plainValue = await c.homDecrypt(decryptParams)
console.log(plainValue)
encyptParms.schemeType = 'bfv'
heKeypair = await c.genHomEncryptKeypair(encyptParms)
//console.log('bfv',JSON.stringify(heKeypair) )
var encyptParams = {
homEncryptParams:heKeypair.homEncryptParams,
homPublicKey:heKeypair.homPublicKey,
homPlainValue:'120'
}
encryptCipher = await c.homEncrypt(encyptParams)
decryptParams = {
homEncryptParams:heKeypair.homEncryptParams,
homPrivateKey:heKeypair.homPrivateKey,
homCipherText:encryptCipher
}
plainValue = await c.homDecrypt(decryptParams)
console.log(plainValue)
}catch(err){
console.error(err)
}
}