private String strValueOf(SecureString def) { if (def == null) return null; return def.value(); }
public static String value(SecureString string, KeyPair key) { if (string == null) return null; if (!(string instanceof CryptedString)) return string.value(); return ((CryptedString)string).value(key); }
public static String encode(METHOD method, SecureString in, String secret) { return encode(method, in.value(), secret); }
public String valueAsString() { SecureString v = value(); return v == null ? null : v.value(); }
default String decrypt(PemPriv key, PemBlock encoded, SecureString passphrase) throws MException { return decrypt(key, encoded, passphrase == null ? null : passphrase.value()); };
default PemBlock sign(PemPriv key, String text, SecureString passphrase) throws MException { return sign(key, text, passphrase == null ? null : passphrase.value()); }
public static String encode(METHOD method, String in, SecureString secret) { return encode(method, in, secret.value()); }
protected void saveEntry(VaultEntry entry) throws IOException { File file = new File(folder,entry.getId().toString()); FileOutputStream parent = new FileOutputStream(file); OutputStream os = MCrypt.createCipherOutputStream(parent, passphrase.value()); ObjectOutputStream oos = new ObjectOutputStream(os); oos.writeInt(version); oos.writeUTF(entry.getId().toString()); oos.writeUTF(entry.getType()); oos.writeUTF(entry.getDescription()); oos.writeObject(entry.getValue()); oos.flush(); parent.close(); }
@Override public void doSave() throws IOException { FileOutputStream parent = new FileOutputStream(file); OutputStream os = MCrypt.createCipherOutputStream(parent, passphrase.value()); ObjectOutputStream oos = new ObjectOutputStream(os); oos.writeInt(1); // version oos.writeUTF(name); oos.writeInt(entries.size()); for (VaultEntry entry : entries.values()) { oos.writeUTF(entry.getId().toString()); oos.writeUTF(entry.getType()); oos.writeUTF(entry.getDescription()); oos.writeObject(entry.getValue()); } oos.flush(); parent.close(); }
protected void loadEntry(File file) throws IOException { FileInputStream parent = new FileInputStream(file); InputStream is = MCrypt.createCipherInputStream(parent, passphrase.value()); ObjectInputStream ois = new ObjectInputStream(is); try { VaultEntry entry = new FileEntry(version,ois); addEntry(entry); } catch (Exception e) { log().w(file,e); } parent.close(); }
@Override public void doLoad() throws IOException { FileInputStream parent = new FileInputStream(file); InputStream is = MCrypt.createCipherInputStream(parent, passphrase.value()); ObjectInputStream ois = new ObjectInputStream(is); name = ois.readUTF(); int size = ois.readInt(); entries.clear(); for (int i = 0; i < size; i++) { VaultEntry entry = new FileEntry(ois); try { addEntry(entry); } catch (MException e) { log().d(entry,e); } } parent.close(); }
try { if (ifc == AsyncKey.class && MVault.TYPE_RSA_PRIVATE_KEY.equals(entry.getType())) { return (T) MCrypt.loadPrivateRsaKey(entry.getValue().value()); return (T) MCrypt.loadPrivateRsaKey(entry.getValue().value()); return (T) PemUtil.cipherPrivFromString(entry.getValue().value()); return (T) PemUtil.cipherPubFromString(entry.getValue().value()); return (T) PemUtil.signPrivFromString(entry.getValue().value()); return (T) PemUtil.signPubFromString(entry.getValue().value());