public static byte[] encrypt(ECPoint toPub, byte[] plaintext, byte[] macData) { ECKeyPairGenerator eGen = new ECKeyPairGenerator(); SecureRandom random = new SecureRandom(); KeyGenerationParameters gParam = new ECKeyGenerationParameters(CURVE, random); eGen.init(gParam); byte[] IV = new byte[KEY_SIZE/8]; new SecureRandom().nextBytes(IV); AsymmetricCipherKeyPair ephemPair = eGen.generateKeyPair(); BigInteger prv = ((ECPrivateKeyParameters)ephemPair.getPrivate()).getD(); ECPoint pub = ((ECPublicKeyParameters)ephemPair.getPublic()).getQ(); EthereumIESEngine iesEngine = makeIESEngine(true, toPub, prv, IV); ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(CURVE, random); ECKeyPairGenerator generator = new ECKeyPairGenerator(); generator.init(keygenParams); ECKeyPairGenerator gen = new ECKeyPairGenerator(); gen.init(new ECKeyGenerationParameters(ECKey.CURVE, random)); byte[] cipher; try { cipher = iesEngine.processBlock(plaintext, 0, plaintext.length, macData); ByteArrayOutputStream bos = new ByteArrayOutputStream(); bos.write(pub.getEncoded(false)); bos.write(IV); bos.write(cipher); return bos.toByteArray(); } catch (InvalidCipherTextException e) { throw Throwables.propagate(e); } catch (IOException e) { throw Throwables.propagate(e); } }
public void init( KeyGenerationParameters param) { ECKeyGenerationParameters ecP = (ECKeyGenerationParameters)param; this.random = ecP.getRandom(); this.params = ecP.getDomainParameters(); }
public void init( KeyGenerationParameters param) { ECKeyGenerationParameters ecP = (ECKeyGenerationParameters)param; this.random = ecP.getRandom(); this.params = ecP.getDomainParameters(); if (this.random == null) { this.random = new SecureRandom(); } }
public static byte[] encrypt(ECPoint toPub, byte[] plaintext) throws InvalidCipherTextException, IOException { ECKeyPairGenerator eGen = new ECKeyPairGenerator(); SecureRandom random = new SecureRandom(); KeyGenerationParameters gParam = new ECKeyGenerationParameters(curve, random); eGen.init(gParam); byte[] IV = new byte[KEY_SIZE/8]; new SecureRandom().nextBytes(IV); AsymmetricCipherKeyPair ephemPair = eGen.generateKeyPair(); BigInteger prv = ((ECPrivateKeyParameters)ephemPair.getPrivate()).getD(); ECPoint pub = ((ECPublicKeyParameters)ephemPair.getPublic()).getQ(); EthereumIESEngine iesEngine = makeIESEngine(true, toPub, prv, IV); ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(curve, random); ECKeyPairGenerator generator = new ECKeyPairGenerator(); generator.init(keygenParams); ECKeyPairGenerator gen = new ECKeyPairGenerator(); gen.init(new ECKeyGenerationParameters(ECKey.CURVE, random)); byte[] cipher = iesEngine.processBlock(plaintext, 0, plaintext.length); ByteArrayOutputStream bos = new ByteArrayOutputStream(); bos.write(pub.getEncoded(false)); bos.write(IV); bos.write(cipher); return bos.toByteArray(); }
KeyGenerationParameters gParam = new ECKeyGenerationParameters(ECKey.CURVE, new SecureRandom()); ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(ECKey.CURVE, new SecureRandom()); ECKeyPairGenerator generator = new ECKeyPairGenerator(); generator.init(keygenParams); gen.init(new ECKeyGenerationParameters(ECKey.CURVE, new SecureRandom()));
KeyGenerationParameters gParam = new ECKeyGenerationParameters(CURVE, random); eGen.init(gParam);
KeyGenerationParameters gParam = new ECKeyGenerationParameters(ECKey.CURVE, new SecureRandom()); ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(ECKey.CURVE, new SecureRandom()); ECKeyPairGenerator generator = new ECKeyPairGenerator(); generator.init(keygenParams); gen.init(new ECKeyGenerationParameters(ECKey.CURVE, new SecureRandom()));
public static AsymmetricCipherKeyPair generateECKeyPair(SecureRandom random, ECDomainParameters ecParams) { ECKeyPairGenerator keyPairGenerator = new ECKeyPairGenerator(); keyPairGenerator.init(new ECKeyGenerationParameters(ecParams, random)); return keyPairGenerator.generateKeyPair(); }
public static byte[] encrypt(ECPoint toPub, byte[] plaintext, byte[] macData) { ECKeyPairGenerator eGen = new ECKeyPairGenerator(); SecureRandom random = new SecureRandom(); KeyGenerationParameters gParam = new ECKeyGenerationParameters(CURVE, random); eGen.init(gParam); byte[] IV = new byte[KEY_SIZE / 8]; new SecureRandom().nextBytes(IV); AsymmetricCipherKeyPair ephemPair = eGen.generateKeyPair(); BigInteger prv = ((ECPrivateKeyParameters) ephemPair.getPrivate()).getD(); ECPoint pub = ((ECPublicKeyParameters) ephemPair.getPublic()).getQ(); EthereumIESEngine iesEngine = makeIESEngine(true, toPub, prv, IV); ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(CURVE, random); ECKeyPairGenerator generator = new ECKeyPairGenerator(); generator.init(keygenParams); ECKeyPairGenerator gen = new ECKeyPairGenerator(); gen.init(new ECKeyGenerationParameters(ECKey.CURVE, random)); byte[] cipher; try { cipher = iesEngine.processBlock(plaintext, 0, plaintext.length, macData); ByteArrayOutputStream bos = new ByteArrayOutputStream(); bos.write(pub.getEncoded(false)); bos.write(IV); bos.write(cipher); return bos.toByteArray(); } catch (InvalidCipherTextException | IOException e) { throw new RuntimeException(e); } }
public AsymmetricCipherKeyPair generateKeyPair() { ECKeyPairGenerator keyPairGenerator = new ECKeyPairGenerator(); keyPairGenerator.init(new ECKeyGenerationParameters(ecDomainParameters, crypto.getSecureRandom())); return keyPairGenerator.generateKeyPair(); } }
protected AsymmetricCipherKeyPair generateECKeyPair(ECDomainParameters ecParams) { ECKeyPairGenerator keyPairGenerator = new ECKeyPairGenerator(); ECKeyGenerationParameters keyGenerationParameters = new ECKeyGenerationParameters(ecParams, context.getSecureRandom()); keyPairGenerator.init(keyGenerationParameters); return keyPairGenerator.generateKeyPair(); }
public static byte[] encrypt(ECPoint toPub, byte[] plaintext, byte[] macData) { ECKeyPairGenerator eGen = new ECKeyPairGenerator(); SecureRandom random = new SecureRandom(); KeyGenerationParameters gParam = new ECKeyGenerationParameters(CURVE, random); eGen.init(gParam); byte[] IV = new byte[KEY_SIZE/8]; new SecureRandom().nextBytes(IV); AsymmetricCipherKeyPair ephemPair = eGen.generateKeyPair(); BigInteger prv = ((ECPrivateKeyParameters)ephemPair.getPrivate()).getD(); ECPoint pub = ((ECPublicKeyParameters)ephemPair.getPublic()).getQ(); EthereumIESEngine iesEngine = makeIESEngine(true, toPub, prv, IV); ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(CURVE, random); ECKeyPairGenerator generator = new ECKeyPairGenerator(); generator.init(keygenParams); ECKeyPairGenerator gen = new ECKeyPairGenerator(); gen.init(new ECKeyGenerationParameters(ECKey.CURVE, random)); byte[] cipher; try { cipher = iesEngine.processBlock(plaintext, 0, plaintext.length, macData); ByteArrayOutputStream bos = new ByteArrayOutputStream(); bos.write(pub.getEncoded(false)); bos.write(IV); bos.write(cipher); return bos.toByteArray(); } catch (InvalidCipherTextException e) { } catch (IOException e) { } return null; }
protected ECKeyGenerationParameters createKeyGenParamsJCE(java.security.spec.ECParameterSpec p, SecureRandom r) { ECCurve curve = EC5Util.convertCurve(p.getCurve()); ECPoint g = EC5Util.convertPoint(curve, p.getGenerator(), false); BigInteger n = p.getOrder(); BigInteger h = BigInteger.valueOf(p.getCofactor()); ECDomainParameters dp = new ECDomainParameters(curve, g, n, h); return new ECKeyGenerationParameters(dp, r); }
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(); }
keyGen.init(new ECKeyGenerationParameters(privKey.getParameters(), this.random));
keyGen.init(new ECKeyGenerationParameters(privKey.getParameters(), this.random));
protected ECKeyGenerationParameters createKeyGenParamsBC(ECParameterSpec p, SecureRandom r) { return new ECKeyGenerationParameters(new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH()), r); }
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); }
public CryptoImpl() { // populate the cipher set map CipherSet2aImpl set2a = new CipherSet2aImpl(this); mCipherSetMap.put(set2a.getCipherSetId(), set2a); // initialize elliptic curve parameters and generator mECNamedCurveParameterSpec = ECNamedCurveTable.getParameterSpec("prime256v1"); mECGenerator = new ECKeyPairGenerator(); mECDomainParameters = new ECDomainParameters( mECNamedCurveParameterSpec.getCurve(), mECNamedCurveParameterSpec.getG(), mECNamedCurveParameterSpec.getN() ); mECKeyGenerationParameters = new ECKeyGenerationParameters(mECDomainParameters, random); mECGenerator.init(mECKeyGenerationParameters); }
public CipherSet2aImpl(Crypto crypto) { mCrypto = crypto; // initialize elliptic curve parameters and generator mECNamedCurveParameterSpec = ECNamedCurveTable.getParameterSpec("prime256v1"); mECGenerator = new ECKeyPairGenerator(); mECDomainParameters = new ECDomainParameters( mECNamedCurveParameterSpec.getCurve(), mECNamedCurveParameterSpec.getG(), mECNamedCurveParameterSpec.getN() ); mECKeyGenerationParameters = new ECKeyGenerationParameters(mECDomainParameters, mRandom); mECGenerator.init(mECKeyGenerationParameters); }