mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-10-01 01:35:48 -04:00
Create task to generate key pairs (#823)
This commit is contained in:
parent
697828d773
commit
82eb081089
@ -436,6 +436,11 @@ configure(project(':core')) {
|
||||
systemProperty 'jdk.attach.allowAttachSelf', true
|
||||
}
|
||||
|
||||
task generateKeypairs(type: JavaExec) {
|
||||
mainClass = 'haveno.core.util.GenerateKeyPairs'
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
}
|
||||
|
||||
task havenoDeps {
|
||||
doLast {
|
||||
// get monero binaries download url
|
||||
|
@ -19,16 +19,6 @@ package haveno.common.crypto;
|
||||
|
||||
import haveno.common.util.Hex;
|
||||
import haveno.common.util.Utilities;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.OAEPParameterSpec;
|
||||
import javax.crypto.spec.PSource;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.InvalidKeyException;
|
||||
@ -43,10 +33,17 @@ import java.security.spec.InvalidKeySpecException;
|
||||
import java.security.spec.MGF1ParameterSpec;
|
||||
import java.security.spec.X509EncodedKeySpec;
|
||||
import java.util.Arrays;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.OAEPParameterSpec;
|
||||
import javax.crypto.spec.PSource;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class Encryption {
|
||||
private static final Logger log = LoggerFactory.getLogger(Encryption.class);
|
||||
|
||||
public static final String ASYM_KEY_ALGO = "RSA";
|
||||
private static final String ASYM_CIPHER = "RSA/ECB/OAEPWithSHA-256AndMGF1PADDING";
|
||||
|
||||
|
@ -12,29 +12,29 @@ import org.bitcoinj.core.Utils;
|
||||
import haveno.common.crypto.Encryption;
|
||||
|
||||
/**
|
||||
* This utility generates and prints public/private keypairs
|
||||
* This utility generates and prints public/private key-pairs
|
||||
* which can be used to register arbitrators on the network.
|
||||
*/
|
||||
public class GenerateKeypairs {
|
||||
public class GenerateKeyPairs {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// generate public/private keypairs
|
||||
List<SecretKey> secretKeys = new ArrayList<SecretKey>();
|
||||
// generate public/private key-pairs
|
||||
List<SecretKey> secretKeys = new ArrayList<>();
|
||||
for (int i = 0; i < 20; i++) {
|
||||
secretKeys.add(Encryption.generateSecretKey(256));
|
||||
}
|
||||
|
||||
// print keypairs
|
||||
// print key-pairs
|
||||
System.out.println("Private keys:");
|
||||
for (SecretKey sk : secretKeys) {
|
||||
String privKey = Utils.HEX.encode(sk.getEncoded());
|
||||
System.out.println(privKey);
|
||||
String privateKey = Utils.HEX.encode(sk.getEncoded());
|
||||
System.out.println(privateKey);
|
||||
}
|
||||
System.out.println("Corresponding public keys:");
|
||||
for (SecretKey sk : secretKeys) {
|
||||
String privKey = Utils.HEX.encode(sk.getEncoded());
|
||||
ECKey ecKey = ECKey.fromPrivate(new BigInteger(1, Utils.HEX.decode(privKey)));
|
||||
String privateKey = Utils.HEX.encode(sk.getEncoded());
|
||||
ECKey ecKey = ECKey.fromPrivate(new BigInteger(1, Utils.HEX.decode(privateKey)));
|
||||
String pubKey = Utils.HEX.encode(ecKey.getPubKey());
|
||||
System.out.println(pubKey);
|
||||
}
|
Loading…
Reference in New Issue
Block a user