Search in sources :

Example 6 with WalletKeyPair

use of snowblossom.proto.WalletKeyPair in project snowblossom by snowblossomcoin.

the class KeyUtil method generateWalletStandardECKey.

public static WalletKeyPair generateWalletStandardECKey() {
    KeyPair key_pair = KeyUtil.generateECCompressedKey();
    ByteString public_encoded = KeyUtil.getCompressedPublicKeyEncoding(key_pair.getPublic());
    WalletKeyPair wkp = WalletKeyPair.newBuilder().setPublicKey(KeyUtil.getCompressedPublicKeyEncoding(key_pair.getPublic())).setPrivateKey(ByteString.copyFrom(key_pair.getPrivate().getEncoded())).setSignatureType(SignatureUtil.SIG_TYPE_ECDSA_COMPRESSED).build();
    return wkp;
}
Also used : WalletKeyPair(snowblossom.proto.WalletKeyPair) WalletKeyPair(snowblossom.proto.WalletKeyPair) ByteString(com.google.protobuf.ByteString)

Example 7 with WalletKeyPair

use of snowblossom.proto.WalletKeyPair in project snowblossom by snowblossomcoin.

the class KeyUtil method generateWalletDSAKey.

public static WalletKeyPair generateWalletDSAKey() {
    try {
        KeyPairGenerator key_gen = KeyPairGenerator.getInstance("DSA", Globals.getCryptoProviderName());
        key_gen.initialize(3072);
        KeyPair key_pair = key_gen.genKeyPair();
        WalletKeyPair wkp = WalletKeyPair.newBuilder().setPublicKey(ByteString.copyFrom(key_pair.getPublic().getEncoded())).setPrivateKey(ByteString.copyFrom(key_pair.getPrivate().getEncoded())).setSignatureType(SignatureUtil.SIG_TYPE_DSA).build();
        return wkp;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : WalletKeyPair(snowblossom.proto.WalletKeyPair) WalletKeyPair(snowblossom.proto.WalletKeyPair)

Example 8 with WalletKeyPair

use of snowblossom.proto.WalletKeyPair in project snowblossom by snowblossomcoin.

the class KeyUtil method generateWalletRSAKey.

public static WalletKeyPair generateWalletRSAKey(int key_len) {
    try {
        RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(key_len, RSAKeyGenParameterSpec.F4);
        KeyPairGenerator key_gen = KeyPairGenerator.getInstance("RSA", Globals.getCryptoProviderName());
        key_gen.initialize(spec);
        KeyPair key_pair = key_gen.genKeyPair();
        WalletKeyPair wkp = WalletKeyPair.newBuilder().setPublicKey(ByteString.copyFrom(key_pair.getPublic().getEncoded())).setPrivateKey(ByteString.copyFrom(key_pair.getPrivate().getEncoded())).setSignatureType(SignatureUtil.SIG_TYPE_RSA).build();
        return wkp;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : WalletKeyPair(snowblossom.proto.WalletKeyPair) WalletKeyPair(snowblossom.proto.WalletKeyPair) RSAKeyGenParameterSpec(java.security.spec.RSAKeyGenParameterSpec)

Example 9 with WalletKeyPair

use of snowblossom.proto.WalletKeyPair in project snowblossom by snowblossomcoin.

the class KeyUtil method generateWalletDSTU4145Key.

public static WalletKeyPair generateWalletDSTU4145Key(int curve) {
    try {
        ECGenParameterSpec spec = new ECGenParameterSpec("1.2.804.2.1.1.1.1.3.1.1.2." + curve);
        KeyPairGenerator key_gen = KeyPairGenerator.getInstance("DSTU4145", Globals.getCryptoProviderName());
        key_gen.initialize(spec);
        KeyPair key_pair = key_gen.genKeyPair();
        WalletKeyPair wkp = WalletKeyPair.newBuilder().setPublicKey(ByteString.copyFrom(key_pair.getPublic().getEncoded())).setPrivateKey(ByteString.copyFrom(key_pair.getPrivate().getEncoded())).setSignatureType(SignatureUtil.SIG_TYPE_DSTU4145).build();
        return wkp;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : WalletKeyPair(snowblossom.proto.WalletKeyPair) WalletKeyPair(snowblossom.proto.WalletKeyPair) ECGenParameterSpec(java.security.spec.ECGenParameterSpec)

Example 10 with WalletKeyPair

use of snowblossom.proto.WalletKeyPair in project snowblossom by snowblossomcoin.

the class CertGen method getServerSSLContext.

public static SslContext getServerSSLContext(WalletDatabase db) throws Exception {
    if (db.getKeysCount() != 1)
        throw new RuntimeException("Unexpected number of keys in wallet db");
    if (db.getAddressesCount() != 1)
        throw new RuntimeException("Unexpected number of addresses in wallet db");
    WalletKeyPair wkp = db.getKeys(0);
    AddressSpec address_spec = db.getAddresses(0);
    WalletKeyPair tls_wkp = KeyUtil.generateWalletRSAKey(2048);
    KeyPair tls_pair = KeyUtil.decodeKeypair(tls_wkp);
    X509Certificate cert = generateSelfSignedCert(wkp, tls_wkp, address_spec);
    // System.out.println(cert);
    ByteString pem_cert = pemCodeCert(cert);
    ByteString pem_prv = pemCodeECPrivateKey(tls_pair.getPrivate());
    return GrpcSslContexts.forServer(pem_cert.newInput(), pem_prv.newInput()).build();
}
Also used : WalletKeyPair(snowblossom.proto.WalletKeyPair) KeyPair(java.security.KeyPair) WalletKeyPair(snowblossom.proto.WalletKeyPair) ByteString(com.google.protobuf.ByteString) AddressSpec(snowblossom.proto.AddressSpec) X509Certificate(java.security.cert.X509Certificate)

Aggregations

WalletKeyPair (snowblossom.proto.WalletKeyPair)19 ByteString (com.google.protobuf.ByteString)9 Test (org.junit.Test)8 KeyPair (java.security.KeyPair)2 ECGenParameterSpec (java.security.spec.ECGenParameterSpec)2 RSAKeyGenParameterSpec (java.security.spec.RSAKeyGenParameterSpec)2 AddressSpec (snowblossom.proto.AddressSpec)2 X509Certificate (java.security.cert.X509Certificate)1 ECParameterSpec (java.security.spec.ECParameterSpec)1 PKCS8EncodedKeySpec (java.security.spec.PKCS8EncodedKeySpec)1 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 Cipher (javax.crypto.Cipher)1 ChildNumber (org.bitcoinj.crypto.ChildNumber)1 DeterministicHierarchy (org.bitcoinj.crypto.DeterministicHierarchy)1 DeterministicKey (org.bitcoinj.crypto.DeterministicKey)1