Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F97868583
ClientTestSimple.java
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Jan 6, 23:38
Size
6 KB
Mime Type
text/x-c
Expires
Wed, Jan 8, 23:38 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
23424211
Attached To
R3229 Genome Privacy - SHCS App
ClientTestSimple.java
View Options
import
utils.ClientProperties
;
public
class
ClientTestSimple
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
ClientProperties
props
=
new
ClientProperties
(
"config/config_client.fry.properties"
);
// testSecrets(props);
// testCryptoSimple(props);
// testPartial(props);
// testDecryption(props);
// testHLAs(props);
testSNPs
(
props
);
}
public
static
void
testSNPs
(
ClientProperties
props
)
throws
Exception
{
// int patientId = 19632;
//
// MedUnit mu = new MedUnit(props, -1);
// ECElGamal ecceg = mu.getScheme(patientId);
//
// JSONConnection connect = mu.getConnectSPU();
//
// ArrayList<MarkerEncrypted> markersEnc = new ArrayList<>();
// MarkerEncrypted myMarker = new MarkerEncrypted("rs10211");
// markersEnc.add(myMarker);
// RequestSNPandCF rqt = new RequestSNPandCF(patientId, 0, 0, markersEnc, new ArrayList<Integer>());
//
// JSONObject jsonRqt = new JSONObject();
// jsonRqt.put(Request.JSON_KEY_TYPE, Type.SNP);
// jsonRqt.put(Request.JSON_KEY_RQT, rqt);
// JSONObject jsonAwr = connect.sendReceive(jsonRqt);
// ReplySNPandCF reply = (ReplySNPandCF) jsonAwr.get(Reply.JSON_KEY_REP);
// HashMap<MarkerEncrypted, FragmentEncoded> map = reply.getEncryptedSNPByMarker();
//
// FragmentEncoded encoded = map.get(myMarker);
// RequestDecryption rqtDec = new RequestDecryption(patientId, -1, 0);
// rqtDec.add(encoded);
//
// JSONObject jsonRqtDec = new JSONObject();
// jsonRqtDec.put(Request.JSON_KEY_TYPE, Type.SNP);
// jsonRqtDec.put(Request.JSON_KEY_RQT, rqtDec);
//
// JSONObject jsonDec = connect.sendReceive(jsonRqtDec);
// ReplyDecryption replyDec = (ReplyDecryption) jsonDec.get(Reply.JSON_KEY_REP);
// FragmentPartial partial = replyDec.getPartialCiphers().get(0).decodeFragment(ecceg);
// BigInteger msg = ecceg.fullyDecrypt(partial);
// System.out.println(msg);
}
public
static
void
testHLAs
(
ClientProperties
props
)
{
// int patiendId = 19632;
//
// MedUnit mu = new MedUnit(props, 0);
//
// String[] hlas = mu.runHLA(patiendId);
// System.out.println(Arrays.toString(hlas));
}
// public static void testSecrets(ClientProperties props) {
// ECCEGKeyGenerator keyGen = new ECCEGKeyGenerator(props.getCurve());
//
// KeyPair pair = keyGen.generateKey();
// BigInteger secret = keyGen.getSecret();
// BigInteger order = keyGen.getOrder();
//
// System.out.println(secret);
// BigInteger composed = BigInteger.valueOf(2L).multiply(pair.getSecretMU().getPrivKey()).subtract(pair.getSecretSPU().getPrivKey()).mod(order);
// System.out.println(composed);
// }
public
static
void
testDecryption
(
ClientProperties
props
)
throws
Exception
{
// int patientId = 19632;
// MedUnit mu = new MedUnit(props, 0);
// ECElGamal ecceg = mu.getScheme(patientId);
//
// BigInteger message = new BigInteger("12345");
//
// FragmentEncrypted encrypt = ecceg.encrypt(message);
//
// RequestDecryption rqt = new RequestDecryption(patientId, 0, 0);
// rqt.add(encrypt);
//
// JSONObject jsonRqt = new JSONObject();
// jsonRqt.put(Request.JSON_KEY_TYPE, Type.DECRYPT);
// jsonRqt.put(Request.JSON_KEY_RQT, rqt);
//
// JSONConnection connectSPU = mu.getConnectSPU();
// JSONObject jsonAwr = connectSPU.sendReceive(jsonRqt);
// System.out.println(jsonAwr.toString());
//
// ReplyDecryption reply = (ReplyDecryption) jsonAwr.get(Reply.JSON_KEY_REP);
// FragmentPartialEncoded partialEncoded = reply.getPartialCiphers().get(0);
// FragmentPartial partial = partialEncoded.decodeFragment(ecceg);
//
// BigInteger messageClear = ecceg.fullyDecrypt(partial);
// System.out.println(messageClear);
}
public
static
void
testPartial
(
ClientProperties
props
)
throws
Exception
{
//
// File filepathReverse = new File(props.getProperty(ConfigProperties.KEY_REVERSE_TABLE));
// String curve = props.getCurve();
//
// ECCEGKeyGenerator generator = new ECCEGKeyGenerator(curve);
// KeyPair pair = generator.generateKey();
//
// ECElGamal eccegNeutral = new ECElGamal(curve);
// eccegNeutral.setpPubKey(pair.getPubKey());
//
// ECElGamal eccegSPU = new ECElGamal(curve);
// eccegSPU.setpPubKey(pair.getPubKey());
// eccegSPU.setSecretShare(pair.getSecretSPU());
//
// ECElGamal eccegMU = new ECElGamal(curve);
// eccegMU.setpPubKey(pair.getPubKey());
// eccegMU.setSecretShare(pair.getSecretMU());
// eccegMU.initReverseDLTable();
//// eccegMU.readReverseTable(filepathReverse);
//
// BigInteger message = new BigInteger("12");
// FragmentEncrypted encrypt = eccegNeutral.encrypt(message);
//
//
// FragmentPartial partialSPU = eccegSPU.partialDecrypt(encrypt);
// FragmentPartial partialMU = eccegMU.partialDecrypt(encrypt);
//
// BigInteger message3 = eccegMU.aggregateDecryption(partialMU, partialSPU);
// System.out.println(message3);
//// BigInteger message2 = eccegMU.fullyDecrypt(partialSPU);
//
//// System.out.println(message2);
}
// public static void testCryptoSimple(ClientProperties props) throws Exception {
// String curve = props.getCurve();
//
// ECCEGKeyGenerator keyGen = new ECCEGKeyGenerator(curve);
// KeyPair pair = keyGen.generateKey();
//
// ECElGamal eccegMU = new ECElGamal(curve);
// eccegMU.setpPubKey(pair.getPubKey());
// eccegMU.setSecretShare(pair.getSecretMU());
//
// ECElGamal eccegSPU = new ECElGamal(curve);
// eccegSPU.setpPubKey(pair.getPubKey());
// eccegSPU.setSecretShare(pair.getSecretSPU());
// eccegSPU.readReverseTable(new File(props.getProperty(ConfigProperties.KEY_REVERSE_TABLE)));
//
//
// ECElGamal eccegAlt = new ECElGamal(NISTNamedCurves.getByName("P-521"), keyGen.getSecret());
// eccegAlt.readReverseTable(new File(props.getProperty(ConfigProperties.KEY_REVERSE_TABLE)));
//
//// ECElGamal ecceg = new ECElGamal(curve);
//// ecceg.initReverseDLTable();
//
// BigInteger msg = new BigInteger("1999");
// FragmentEncrypted encrypted = eccegAlt.encrypt(msg);
//
// // shared decryption
// FragmentPartial partialMU = eccegMU.partialDecrypt(encrypted);
//// FragmentPartial partialSPU = eccegSPU.partialDecrypt(encrypted);
//
//// BigInteger msgComp = eccegSPU.aggregateDecryption(partialMU, partialSPU);
// BigInteger msgComp = eccegSPU.fullyDecrypt(partialMU);
// System.out.println(msgComp);
//
//
// // decryption with secret
// BigInteger msg2 = eccegAlt.decrypt(encrypted);
// System.out.println(msg2);
//
// }
}
Event Timeline
Log In to Comment