예제 #1
0
 /**
  * Get <code>ECPublicKeyParameters</code>
  *
  * @return parameters for use with BouncyCastle API
  * @see ECPublicKeyParameters
  */
 public CipherParameters getParameters() {
   if (!isInitialized()) {
     CryptoException.throwIt(CryptoException.UNINITIALIZED_KEY);
   }
   ECDomainParameters dp = getDomainParameters();
   return new ECPublicKeyParameters(
       dp.getCurve().decodePoint(w.getBytes(JCSystem.CLEAR_ON_RESET)), dp);
 }
예제 #2
0
파일: Address.java 프로젝트: gitonio/btcJ
  public static byte[] privateKeyToPublicKey(String private_key, boolean compressed) {
    byte[] privateKeyBytes = null;

    try {
      privateKeyBytes = org.apache.commons.codec.binary.Hex.decodeHex(private_key.toCharArray());
    } catch (DecoderException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    X9ECParameters ecp = SECNamedCurves.getByName("secp256k1");
    ECDomainParameters domainParams =
        new ECDomainParameters(ecp.getCurve(), ecp.getG(), ecp.getN(), ecp.getH(), ecp.getSeed());

    ECPrivateKeyParameters privateKey =
        new ECPrivateKeyParameters(new BigInteger(1, privateKeyBytes), domainParams);
    System.out.println(privateKey.getD());
    byte[] publicKeyBIBytes = privateKey.getD().toByteArray();
    ECPoint Q = domainParams.getG().multiply(new BigInteger(publicKeyBIBytes));

    byte[] publicKeyBytes = Q.getEncoded(compressed);
    return publicKeyBytes;
  }
  public ECKeyGenerationParameters(ECDomainParameters domainParams, SecureRandom random) {
    super(random, domainParams.getN().bitLength());

    this.domainParams = domainParams;
  }
예제 #4
0
 private byte[] bigIntToBytes(BigInteger r) {
   return converter.integerToBytes(r, converter.getByteLength(parameters.getG().getX()));
 }