org.spongycastle.jce.spec.ECPrivateKeySpec Java Examples

The following examples show how to use org.spongycastle.jce.spec.ECPrivateKeySpec. 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: SpongyCryptography.java    From Jabit with Apache License 2.0 6 votes vote down vote up
@Override
public byte[] getSignature(byte[] data, PrivateKey privateKey) {
    try {
        ECParameterSpec spec = new ECParameterSpec(
            EC_CURVE_PARAMETERS.getCurve(),
            EC_CURVE_PARAMETERS.getG(),
            EC_CURVE_PARAMETERS.getN(),
            EC_CURVE_PARAMETERS.getH(),
            EC_CURVE_PARAMETERS.getSeed()
        );

        BigInteger d = keyToBigInt(privateKey.getPrivateSigningKey());
        KeySpec keySpec = new ECPrivateKeySpec(d, spec);
        java.security.PrivateKey privKey = KeyFactory.getInstance(ALGORITHM_ECDSA, provider)
            .generatePrivate(keySpec);

        Signature sig = Signature.getInstance(ALGORITHM_ECDSA, provider);
        sig.initSign(privKey);
        sig.update(data);
        return sig.sign();
    } catch (GeneralSecurityException e) {
        throw new ApplicationException(e);
    }
}
 
Example #2
Source File: ECKeySecp256k1.java    From aion with MIT License 5 votes vote down vote up
private static PrivateKey privateKeyFromBigInteger(BigInteger priv) {
    if (priv == null) {
        return null;
    } else {
        try {
            return ECKeyFactory.getInstance(SpongyCastleProvider.getInstance())
                    .generatePrivate(new ECPrivateKeySpec(priv, CURVE_SPEC));
        } catch (InvalidKeySpecException ex) {
            throw new AssertionError("Assumed correct key spec statically");
        }
    }
}
 
Example #3
Source File: ECKey.java    From gsc-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static PrivateKey privateKeyFromBigInteger(BigInteger priv) {
    if (priv == null) {
        return null;
    } else {
        try {
            return ECKeyFactory
                    .getInstance(GSCCastleProvider.getInstance())
                    .generatePrivate(new ECPrivateKeySpec(priv,
                            CURVE_SPEC));
        } catch (InvalidKeySpecException ex) {
            throw new AssertionError("Assumed correct key spec statically");
        }
    }
}
 
Example #4
Source File: ECKey.java    From wkcwallet-java with Apache License 2.0 5 votes vote down vote up
private static PrivateKey privateKeyFromBigInteger(BigInteger priv) {
    if (priv == null) {
        return null;
    } else {
        try {
            return ECKeyFactory.getInstance(SpongyCastleProvider.getInstance()).generatePrivate(
                    new ECPrivateKeySpec(priv, CURVE_SPEC));
        } catch (InvalidKeySpecException ex) {
            throw new AssertionError("Assumed correct key spec statically");
        }
    }
}
 
Example #5
Source File: ECKey.java    From tron-wallet-android with Apache License 2.0 5 votes vote down vote up
private static PrivateKey privateKeyFromBigInteger(BigInteger priv) {
  if (priv == null) {
    return null;
  } else {
    try {
      return ECKeyFactory
          .getInstance(TronCastleProvider.getInstance())
          .generatePrivate(new ECPrivateKeySpec(priv,
              CURVE_SPEC));
    } catch (InvalidKeySpecException ex) {
      throw new AssertionError("Assumed correct key spec statically");
    }
  }
}
 
Example #6
Source File: ECKey.java    From asf-sdk with GNU General Public License v3.0 5 votes vote down vote up
private static PrivateKey privateKeyFromBigInteger(BigInteger priv) {
  if (priv == null) {
    return null;
  } else {
    try {
      return ECKeyFactory.getInstance(SpongyCastleProvider.getInstance())
          .generatePrivate(new ECPrivateKeySpec(priv, CURVE_SPEC));
    } catch (InvalidKeySpecException ex) {
      throw new AssertionError("Assumed correct key spec statically");
    }
  }
}