@@ -126,60 +126,60 @@ public static String generateKeystore(String password, String path) {
126126 }
127127 }
128128
129- // /**
130- // * 修改keystore密码
131- // * @param keystoreJson
132- // * @param password
133- // * @param newPassword
134- // * @return
135- // */
136- // public static JSON modifyPassword(String keystoreJson, String password,String newPassword){
137- // try {
138- // String prikey = obtainPrikey(keystoreJson,password);
139- // Ed25519PrivateKey privateKey = new Ed25519PrivateKey(Hex.decodeHex(prikey.toCharArray()));
140- // Ed25519PublicKey publicKey = privateKey.generatePublicKey();
141- // if (password.length()>20 || password.length()<8){
142- // JSONObject json = JSON.parseObject("");;
143- // return json;
144- // }else {
145- // byte[] salt = new byte[saltLength];
146- // byte[] iv = new byte[ivLength];
147- // SecureRandom random = new SecureRandom();
148- // random.nextBytes(iv);
149- // SecureRandom sr = new SecureRandom();
150- // sr.nextBytes(salt);
151- // ArgonManage argon2id = new ArgonManage(ArgonManage.Type.ARGON2id, new String(Hex.encodeHex(salt)), newVersion);
152- // AESManage aes = new AESManage(iv);
153- //
154- // byte[] derivedKey = argon2id.hash(newPassword.getBytes());
155- // byte[] cipherPrivKey = aes.encrypt(derivedKey, privateKey.getEncoded());
156- // byte[] mac = SHA3Utility.keccak256(Bytes.concat(
157- // derivedKey,cipherPrivKey
158- // )
159- // );
160- // String b= new String(Hex.encodeHex(iv));
161- //
162- // Crypto crypto = new Crypto(
163- // AESManage.cipher,new String(Hex.encodeHex(cipherPrivKey)),
164- // new Cipherparams(
165- // new String(Hex.encodeHex(iv))
166- // )
167- // );
168- // Kdfparams kdfparams = new Kdfparams(ArgonManage.memoryCost,ArgonManage.timeCost,ArgonManage.parallelism, new String(Hex.encodeHex(salt)));
169- //
170- // com.company.keystore.account.Address ads = new com.company.keystore.account.Address(publicKey);
171- // Keystore ks = new Keystore(ads.getAddress(), crypto, Utils.generateUUID(),
172- // newVersion, new String(Hex.encodeHex(mac)), argon2id.kdf(),kdfparams
173- // );
174- // String jsonString = JSON.toJSONString(ks);
175- // JSONObject json = JSON.parseObject(jsonString);
176- // return json;
177- // }
178- // }catch (Exception e){
179- // JSONObject json = JSON.parseObject("");
180- // return json;
181- // }
182- // }
129+ /**
130+ * 修改keystore密码
131+ * @param keystoreJson
132+ * @param password
133+ * @param newPassword
134+ * @return
135+ */
136+ public static JSON modifyPassword (String keystoreJson , String password ,String newPassword ){
137+ try {
138+ String prikey = obtainPrikey (keystoreJson ,password );
139+ Ed25519PrivateKey privateKey = new Ed25519PrivateKey (Hex .decodeHex (prikey .toCharArray ()));
140+ Ed25519PublicKey publicKey = privateKey .generatePublicKey ();
141+ if (password .length ()>20 || password .length ()<8 ){
142+ JSONObject json = JSON .parseObject ("" );;
143+ return json ;
144+ }else {
145+ byte [] salt = new byte [saltLength ];
146+ byte [] iv = new byte [ivLength ];
147+ SecureRandom random = new SecureRandom ();
148+ random .nextBytes (iv );
149+ SecureRandom sr = new SecureRandom ();
150+ sr .nextBytes (salt );
151+ ArgonManage argon2id = new ArgonManage (ArgonManage .Type .ARGON2id , new String (Hex .encodeHex (salt )), newVersion );
152+ AESManage aes = new AESManage (iv );
153+
154+ byte [] derivedKey = argon2id .hash (newPassword .getBytes ());
155+ byte [] cipherPrivKey = aes .encrypt (derivedKey , privateKey .getEncoded ());
156+ byte [] mac = SHA3Utility .keccak256 (Bytes .concat (
157+ derivedKey ,cipherPrivKey
158+ )
159+ );
160+ String b = new String (Hex .encodeHex (iv ));
161+
162+ Crypto crypto = new Crypto (
163+ AESManage .cipher ,new String (Hex .encodeHex (cipherPrivKey )),
164+ new Cipherparams (
165+ new String (Hex .encodeHex (iv ))
166+ )
167+ );
168+ Kdfparams kdfparams = new Kdfparams (ArgonManage .memoryCost ,ArgonManage .timeCost ,ArgonManage .parallelism , new String (Hex .encodeHex (salt )));
169+
170+ com .company .keystore .account .Address ads = new com .company .keystore .account .Address (publicKey );
171+ Keystore ks = new Keystore (ads .getAddress (), crypto , Utils .generateUUID (),
172+ newVersion , new String (Hex .encodeHex (mac )), argon2id .kdf (),kdfparams
173+ );
174+ String jsonString = JSON .toJSONString (ks );
175+ JSONObject json = JSON .parseObject (jsonString );
176+ return json ;
177+ }
178+ }catch (Exception e ){
179+ JSONObject json = JSON .parseObject ("" );
180+ return json ;
181+ }
182+ }
183183
184184 /*
185185 3.将r1进行两次SHA3-256计算,得到结果r3,
0 commit comments