public void performTest() throws Exception { BigInteger pSubOne = DHStandardGroups.rfc3526_2048.getP().subtract(ONE); for (int i = 0; i < 10; ++i) { BigInteger message = BigIntegers.createRandomInRange(ONE, pSubOne, RND); BigInteger m1 = encDecTest(message); BigInteger m2 = labelledEncDecTest(message, "myRandomLabel"); BigInteger m3 = encDecEncodingTest(message); BigInteger m4 = labelledEncDecEncodingTest(message, "myOtherCoolLabel"); if (!message.equals(m1) || !message.equals(m2) || !message.equals(m3) || !message.equals(m4)) { fail("decrypted message != original message"); } } }
private CramerShoupCiphertext encrypt(BigInteger message, String label) { CramerShoupKeyPairGenerator kpGen = new CramerShoupKeyPairGenerator(); CramerShoupParametersGenerator pGen = new CramerShoupParametersGenerator(); pGen.init(2048, 1, RND); CramerShoupParameters params = pGen.generateParameters(DHStandardGroups.rfc3526_2048); CramerShoupKeyGenerationParameters param = new CramerShoupKeyGenerationParameters(RND, params); kpGen.init(param); keyPair = kpGen.generateKeyPair(); CramerShoupCoreEngine engine = new CramerShoupCoreEngine(); if (label != null) { engine.init(true, keyPair.getPublic(), label); } else { engine.init(true, keyPair.getPublic()); } CramerShoupCiphertext ciphertext = engine.encryptBlock(message); return ciphertext; }
protected DHParameters getDHParameters() { return DHStandardGroups.rfc5114_1024_160; }
protected DHParameters getDHParameters() { return DHStandardGroups.rfc5114_2048_256; }