public static String encodeBase64Content(byte[] value) { return encodeBase64Content(value, false); }
@NotNull static Element setBinaryElementContent(String elementPath, Element parentElement, byte[] value) { try { String b64 = Helpers.encodeBase64Content(value, true); //Find the highest numbered existing content String max = xpath.evaluate("//Binaries/Binary/@ID[not(. < ../../Binary/@ID)][1]", parentElement.getOwnerDocument().getDocumentElement()); Integer newIndex = Integer.valueOf(max) + 1; Element binaries = getElement("//Binaries", parentElement.getOwnerDocument().getDocumentElement(),false); if (binaries == null) { throw new IllegalStateException("Binaries not found"); } Element binary = (Element) binaries.appendChild(binaries.getOwnerDocument().createElement("Binary")); binary.setTextContent(b64); binary.setAttribute("Compressed", "True"); binary.setAttribute("ID", newIndex.toString()); Element result = getElement(elementPath, parentElement, true); result.setAttribute("Ref", newIndex.toString()); return result; } catch (XPathExpressionException e) { throw new IllegalStateException(e); } }
@Override public void write(OutputNode outputNode, KeePassFile.ByteArray bytes) throws Exception { outputNode.setValue(Helpers.encodeBase64Content(bytes.getContent(), false)); } }
if (encryptContent) { String unencrypted = event.asCharacters().getData(); String encrypted = Helpers.encodeBase64Content(encryptor.encrypt(unencrypted.getBytes()), false); event = eventFactory.createCharacters(encrypted);
return Helpers.encodeBase64Content(output, false);
/** * Add a Nonce and a Verifier to a message to make it verifiable * * @param response a message to make verifiable */ void makeVerifiable(Message.Response response) { // we don't have a key? we can't do anything if (getKey() == null) { return; } // The nonce is base64 encoded version of an iv byte[] iv = new SecureRandom().generateSeed(16); response.Nonce = Helpers.encodeBase64Content(iv, false); // The verifier is the base64 encoded encrypted version of the nonce response.Verifier = encryptToBase64(response.Nonce, iv); // encrypt any entries if (response.Entries != null) { for (Message.ResponseEntry entry : response.Entries) { entry.Login = encryptToBase64(entry.Login, iv); entry.Uuid = encryptToBase64(entry.Uuid, iv); entry.Name = encryptToBase64(entry.Name, iv); entry.Password = encryptToBase64(entry.Password, iv); } } }
@Override public void setBinaryProperty(String s, byte[] bytes) { // remove old binary property with same name BinaryProperty bp = getBinaryProp(s, binary); if (bp != null){ binary.remove(bp); } // what is the next free index in the binary store? Integer max = -1; for (KeePassFile.Binaries.Binary binary: database.getBinaries()){ if (binary.getId() > max) { max = binary.getId(); } } max++; // create a new binary to put in the store KeePassFile.Binaries.Binary newBin = new KeePassFile.Binaries.Binary(); newBin.setId(max); newBin.setValue(Helpers.encodeBase64Content(bytes, true)); newBin.setCompressed(true); database.getBinaries().add(newBin); // make a reference to it from the entry BinaryProperty binaryProperty = new BinaryProperty(); binaryProperty.setKey(s); BinaryProperty.Value fieldValue = new BinaryProperty.Value(); fieldValue.setRef(String.valueOf(max)); binaryProperty.setValue(fieldValue); binary.add(binaryProperty); touch(); }