cn.hyperchain.sdk.crypto.jce.ECAlgorithmParameters Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of litesdk Show documentation
Show all versions of litesdk Show documentation
A Java client tool for Hyperchain
package cn.hyperchain.sdk.crypto.jce;
import java.io.IOException;
import java.security.AlgorithmParameters;
import java.security.NoSuchAlgorithmException;
import java.security.spec.ECGenParameterSpec;
import java.security.spec.ECParameterSpec;
import java.security.spec.InvalidParameterSpecException;
public final class ECAlgorithmParameters {
public static final String ALGORITHM = "EC";
public static final String CURVE_NAME = "secp256k1";
private ECAlgorithmParameters() {
}
private static class Holder {
private static final AlgorithmParameters INSTANCE;
private static final ECGenParameterSpec SECP256K1_CURVE
= new ECGenParameterSpec(CURVE_NAME);
static {
try {
INSTANCE = AlgorithmParameters.getInstance(ALGORITHM);
INSTANCE.init(SECP256K1_CURVE);
} catch (NoSuchAlgorithmException ex) {
throw new AssertionError(
"Assumed the JRE supports EC algorithm params");
} catch (InvalidParameterSpecException ex) {
throw new AssertionError(
"Assumed correct key spec statically");
}
}
}
public static ECParameterSpec getParameterSpec() {
try {
return Holder.INSTANCE.getParameterSpec(ECParameterSpec.class);
} catch (InvalidParameterSpecException ex) {
throw new AssertionError(
"Assumed correct key spec statically");
}
}
public static byte[] getASN1Encoding() {
try {
return Holder.INSTANCE.getEncoded();
} catch (IOException ex) {
throw new AssertionError(
"Assumed algo params has been initialized");
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy