org.spongycastle.crypto.generators.ECKeyPairGenerator Java Examples
The following examples show how to use
org.spongycastle.crypto.generators.ECKeyPairGenerator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ECKeyPair.java From BlockchainWallet-Crypto with GNU General Public License v3.0 | 6 votes |
public static ECKeyPair createNew(boolean compressed) { ECKeyPairGenerator generator = new ECKeyPairGenerator(); ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(domain, secureRandom); generator.init(keygenParams); AsymmetricCipherKeyPair keypair = generator.generateKeyPair(); ECPrivateKeyParameters privParams = (ECPrivateKeyParameters) keypair.getPrivate(); ECPublicKeyParameters pubParams = (ECPublicKeyParameters) keypair.getPublic(); ECKeyPair k = new ECKeyPair(); k.priv = privParams.getD(); k.compressed = compressed; ECPoint multiply = CURVE.getG().multiply(k.priv); k.pub = multiply.getEncoded(false); k.pubComp = multiply.getEncoded(true); return k; }
Example #2
Source File: ECKey.java From bcm-android with GNU General Public License v3.0 | 5 votes |
/** * Generates an entirely new keypair with the given {@link SecureRandom} object. Point compression is used so the * resulting public key will be 33 bytes (32 for the co-ordinate and 1 byte to represent the y bit). */ public ECKey(SecureRandom secureRandom) { ECKeyPairGenerator generator = new ECKeyPairGenerator(); ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(CURVE, secureRandom); generator.init(keygenParams); AsymmetricCipherKeyPair keypair = generator.generateKeyPair(); ECPrivateKeyParameters privParams = (ECPrivateKeyParameters) keypair.getPrivate(); ECPublicKeyParameters pubParams = (ECPublicKeyParameters) keypair.getPublic(); priv = privParams.getD(); pub = new LazyECPoint(CURVE.getCurve(), pubParams.getQ().getEncoded(true)); creationTimeSeconds = Utils.currentTimeSeconds(); }
Example #3
Source File: Secp256k1.java From neb.java with GNU Lesser General Public License v3.0 | 5 votes |
public static byte[] GenerateECKey() { ECKeyPairGenerator generator = new ECKeyPairGenerator(); ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(CURVE, Utils.SecureRandom()); generator.init(keygenParams); AsymmetricCipherKeyPair keypair = generator.generateKeyPair(); ECPrivateKeyParameters privParams = (ECPrivateKeyParameters) keypair.getPrivate(); BigInteger privKey = privParams.getD(); return ByteUtils.BigIntegerToBytes(privKey, 32); }
Example #4
Source File: ECKey.java From green_android with GNU General Public License v3.0 | 5 votes |
/** * Generates an entirely new keypair with the given {@link SecureRandom} object. Point compression is used so the * resulting public key will be 33 bytes (32 for the co-ordinate and 1 byte to represent the y bit). */ public ECKey(SecureRandom secureRandom) { ECKeyPairGenerator generator = new ECKeyPairGenerator(); ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(CURVE, secureRandom); generator.init(keygenParams); AsymmetricCipherKeyPair keypair = generator.generateKeyPair(); ECPrivateKeyParameters privParams = (ECPrivateKeyParameters) keypair.getPrivate(); ECPublicKeyParameters pubParams = (ECPublicKeyParameters) keypair.getPublic(); priv = privParams.getD(); pub = new LazyECPoint(CURVE.getCurve(), pubParams.getQ().getEncoded(true)); creationTimeSeconds = Utils.currentTimeSeconds(); }
Example #5
Source File: ECIESCoder.java From wkcwallet-java with Apache License 2.0 | 5 votes |
/** * Encryption equivalent to the Crypto++ default ECIES<ECP> settings: * * DL_KeyAgreementAlgorithm: DL_KeyAgreementAlgorithm_DH<struct ECPPoint,struct EnumToType<enum CofactorMultiplicationOption,0> > * DL_KeyDerivationAlgorithm: DL_KeyDerivationAlgorithm_P1363<struct ECPPoint,0,class P1363_KDF2<class SHA1> > * DL_SymmetricEncryptionAlgorithm: DL_EncryptionAlgorithm_Xor<class HMAC<class SHA1>,0> * DL_PrivateKey: DL_Key<ECPPoint> * DL_PrivateKey_EC<class ECP> * * Used for Whisper V3 */ public static byte[] encryptSimple(ECPoint pub, byte[] plaintext) throws IOException, InvalidCipherTextException { EthereumIESEngine iesEngine = new EthereumIESEngine( new ECDHBasicAgreement(), new MGF1BytesGeneratorExt(new SHA1Digest(), 1), new HMac(new SHA1Digest()), new SHA1Digest(), null); IESParameters p = new IESParameters(null, null, KEY_SIZE); ParametersWithIV parametersWithIV = new ParametersWithIV(p, new byte[0]); iesEngine.setHashMacKey(false); ECKeyPairGenerator eGen = new ECKeyPairGenerator(); SecureRandom random = new SecureRandom(); KeyGenerationParameters gParam = new ECKeyGenerationParameters(CURVE, random); eGen.init(gParam); // AsymmetricCipherKeyPairGenerator testGen = new AsymmetricCipherKeyPairGenerator() { // ECKey priv = ECKey.fromPrivate(Hex.decode("d0b043b4c5d657670778242d82d68a29d25d7d711127d17b8e299f156dad361a")); // // @Override // public void init(KeyGenerationParameters keyGenerationParameters) { // } // // @Override // public AsymmetricCipherKeyPair generateKeyPair() { // return new AsymmetricCipherKeyPair(new ECPublicKeyParameters(priv.getPubKeyPoint(), CURVE), // new ECPrivateKeyParameters(priv.getPrivKey(), CURVE)); // } // }; EphemeralKeyPairGenerator ephemeralKeyPairGenerator = new EphemeralKeyPairGenerator(/*testGen*/eGen, new ECIESPublicKeyEncoder()); iesEngine.init(new ECPublicKeyParameters(pub, CURVE), parametersWithIV, ephemeralKeyPairGenerator); return iesEngine.processBlock(plaintext, 0, plaintext.length); }
Example #6
Source File: ECKey.java From nuls with MIT License | 5 votes |
public ECKey(SecureRandom secureRandom) { ECKeyPairGenerator generator = new ECKeyPairGenerator(); ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(CURVE, secureRandom); generator.init(keygenParams); AsymmetricCipherKeyPair keypair = generator.generateKeyPair(); ECPrivateKeyParameters privParams = (ECPrivateKeyParameters) keypair.getPrivate(); ECPublicKeyParameters pubParams = (ECPublicKeyParameters) keypair.getPublic(); priv = privParams.getD(); pub = pubParams.getQ(); creationTimeSeconds = System.currentTimeMillis(); }
Example #7
Source File: ECKey.java From GreenBits with GNU General Public License v3.0 | 5 votes |
/** * Generates an entirely new keypair with the given {@link SecureRandom} object. Point compression is used so the * resulting public key will be 33 bytes (32 for the co-ordinate and 1 byte to represent the y bit). */ public ECKey(SecureRandom secureRandom) { ECKeyPairGenerator generator = new ECKeyPairGenerator(); ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(CURVE, secureRandom); generator.init(keygenParams); AsymmetricCipherKeyPair keypair = generator.generateKeyPair(); ECPrivateKeyParameters privParams = (ECPrivateKeyParameters) keypair.getPrivate(); ECPublicKeyParameters pubParams = (ECPublicKeyParameters) keypair.getPublic(); priv = privParams.getD(); pub = new LazyECPoint(CURVE.getCurve(), pubParams.getQ().getEncoded(true)); creationTimeSeconds = Utils.currentTimeSeconds(); }
Example #8
Source File: ECKey.java From bitherj with Apache License 2.0 | 5 votes |
/** * Generates an entirely new keypair. Point compression is used so the resulting public key will be 33 bytes * (32 for the co-ordinate and 1 byte to represent the y bit). */ public static ECKey generateECKey(SecureRandom secureRandom) { ECKeyPairGenerator generator = new ECKeyPairGenerator(); ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(CURVE, secureRandom); generator.init(keygenParams); AsymmetricCipherKeyPair keypair = generator.generateKeyPair(); ECPrivateKeyParameters privParams = (ECPrivateKeyParameters) keypair.getPrivate(); ECPublicKeyParameters pubParams = (ECPublicKeyParameters) keypair.getPublic(); BigInteger priv = privParams.getD(); boolean compressed = true; ECKey ecKey = new ECKey(priv, pubParams.getQ().getEncoded(compressed)); ecKey.setCreationTimeSeconds(Utils.currentTimeSeconds()); return ecKey; }
Example #9
Source File: ECKey.java From ethereumj with MIT License | 5 votes |
/** * Generates an entirely new keypair with the given {@link SecureRandom} object. Point compression is used so the * resulting public key will be 33 bytes (32 for the co-ordinate and 1 byte to represent the y bit). */ public ECKey(SecureRandom secureRandom) { ECKeyPairGenerator generator = new ECKeyPairGenerator(); ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(CURVE, secureRandom); generator.init(keygenParams); AsymmetricCipherKeyPair keypair = generator.generateKeyPair(); ECPrivateKeyParameters privParams = (ECPrivateKeyParameters) keypair.getPrivate(); ECPublicKeyParameters pubParams = (ECPublicKeyParameters) keypair.getPublic(); priv = privParams.getD(); pub = CURVE.getCurve().decodePoint(pubParams.getQ().getEncoded(true)); }
Example #10
Source File: ECKeyPair.java From bitseal with GNU General Public License v3.0 | 5 votes |
/** * Generates an entirely new keypair. * */ public ECKeyPair() { ECKeyPairGenerator generator = new ECKeyPairGenerator(); ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(ecParams, secureRandom); generator.init(keygenParams); AsymmetricCipherKeyPair keypair = generator.generateKeyPair(); ECPrivateKeyParameters privParams = (ECPrivateKeyParameters) keypair.getPrivate(); ECPublicKeyParameters pubParams = (ECPublicKeyParameters) keypair.getPublic(); priv = privParams.getD(); pub = pubParams.getQ().getEncoded();// The public key is an encoded point on the elliptic curve. It has no meaning independent of the curve. }