void set(BigInteger yVal, BigInteger pVal, BigInteger qVal, BigInteger gVal) throws KeyczarException { // Initialize the JSON fields y = Base64Coder.encodeWebSafe(yVal.toByteArray()); p = Base64Coder.encodeWebSafe(pVal.toByteArray()); q = Base64Coder.encodeWebSafe(qVal.toByteArray()); g = Base64Coder.encodeWebSafe(gVal.toByteArray()); init(); }
private final void testSessionDecrypt(String subDir) throws Exception { RandomAccessFile activeInput = new RandomAccessFile(testData(subDir) + "/2.session.material", "r"); String sessionMaterial = activeInput.readLine(); activeInput.close(); SessionCrypter crypter = new SessionCrypter( new Crypter(testData(subDir)), Base64Coder.decodeWebSafe(sessionMaterial)); RandomAccessFile primaryInput = new RandomAccessFile(testData(subDir) + "/2.session.ciphertext", "r"); String activeCiphertext = primaryInput.readLine(); primaryInput.close(); byte[] activeDecrypted = crypter.decrypt(Base64Coder.decodeWebSafe(activeCiphertext)); assertEquals(input, new String(activeDecrypted, Keyczar.DEFAULT_ENCODING)); }
private final void testVerifyAttached(String subDir, String hidden) throws Exception { Verifier verifier = new Verifier(testData(subDir)); String hiddenExt = ""; if (hidden != "") hiddenExt = "." + hidden; RandomAccessFile activeInput = new RandomAccessFile(testData(subDir) + "/2" + hiddenExt + ".attached", "r"); String activeSignature = activeInput.readLine(); activeInput.close(); assertTrue( verifier.attachedVerify( Base64Coder.decodeWebSafe(activeSignature), hidden.getBytes(Keyczar.DEFAULT_ENCODING))); }
void init() throws KeyczarException { BigInteger yVal = new BigInteger(Base64Coder.decodeWebSafe(y)); BigInteger pVal = new BigInteger(Base64Coder.decodeWebSafe(p)); BigInteger qVal = new BigInteger(Base64Coder.decodeWebSafe(q)); BigInteger gVal = new BigInteger(Base64Coder.decodeWebSafe(g)); DSAPublicKeySpec spec = new DSAPublicKeySpec(yVal, pVal, qVal, gVal); try { KeyFactory kf = KeyFactory.getInstance(KEY_GEN_ALGORITHM); jcePublicKey = kf.generatePublic(spec); } catch (GeneralSecurityException e) { throw new KeyczarException(e); } byte[] fullHash = Util.prefixHash( Util.stripLeadingZeros(pVal.toByteArray()), Util.stripLeadingZeros(qVal.toByteArray()), Util.stripLeadingZeros(gVal.toByteArray()), Util.stripLeadingZeros(yVal.toByteArray())); System.arraycopy(fullHash, 0, hash, 0, hash.length); }