/** * Helper function to encrypt an identity into a credential (storable * version of an identity) * * @param {String} secret * AES secret used to encrypt the credential. * @return {EbacCredential} * Encrypted credential object. * @memberOf EcIdentity * @method toCredential */ public EbacCredential toCredential(String secret) { EbacCredential c = new EbacCredential(); c.iv = EcAes.newIv(16); c.ppk = EcAesCtr.encrypt(ppk.toPem(), secret, c.iv); c.displayNameIv = EcAes.newIv(16); c.displayName = EcAesCtr.encrypt(displayName, secret, c.iv); return c; }
/** * Writes contact data to localstorage. * * @memberOf EcIdentityManager * @method saveIdentities * @static */ public static void saveIdentities() { Array<Object> c = new Array<Object>(); for (int i = 0; i < ids.$length(); i++) { Object o = new Object(); Map<String, Object> props = JSObjectAdapter.$properties(o); EcIdentity identity = ids.$get(i); props.$put("displayName", identity.displayName); props.$put("ppk", identity.ppk.toPem()); props.$put("source", identity.source); c.push(o); } Global.localStorage.$put("identities", JSGlobal.JSON.stringify(c)); }
private void writeIdentityFile(String folderId, final EcIdentity identity, final Callback0 finished) { File file = BlobHelper.stringToFile(identity.ppk.toPem(), identity.displayName + ".pem", "text/plain"); Object o = new Object(); JSObjectAdapter.$put(o, "id", JSObjectAdapter.$get(identity, "id")); if (JSObjectAdapter.$get(o, "id") == Global.undefined) JSObjectAdapter.$put(o, "parent", folderId); JSObjectAdapter.$put(o, "name", file.name); Array<File> files = new Array<>(); files.push(file); JSObjectAdapter.$put(o, "file", files); hello.api(network + "/" + "me/files", JSObjectAdapter.$get(identity, "id") == Global.undefined ? "post" : "put", o).then(new Callback1<Object>() { @Override public void $invoke(Object r) { JSObjectAdapter.$put(identity, "id", JSObjectAdapter.$get(r, "id")); if (finished != null) finished.$invoke(); } }); }