本文整理了Java中java.security.spec.EllipticCurve.equals()
方法的一些代码示例,展示了EllipticCurve.equals()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EllipticCurve.equals()
方法的具体详情如下:
包路径:java.security.spec.EllipticCurve
类名称:EllipticCurve
方法名:equals
[英]Returns whether the specified object equals to this elliptic curve.
[中]返回指定的对象是否等于此椭圆曲线。
代码示例来源:origin: com.microsoft.azure/azure-keyvault-webkey
private static JsonWebKeyCurveName getCurveFromKeyPair(KeyPair keyPair, Provider provider) {
try {
ECPublicKey key = (ECPublicKey) keyPair.getPublic();
ECParameterSpec spec = key.getParams();
EllipticCurve crv = spec.getCurve();
List<JsonWebKeyCurveName> curveList = Arrays.asList(JsonWebKeyCurveName.P_256, JsonWebKeyCurveName.P_384,
JsonWebKeyCurveName.P_521, JsonWebKeyCurveName.P_256K);
for (JsonWebKeyCurveName curve : curveList) {
ECGenParameterSpec gps = new ECGenParameterSpec(CURVE_TO_SPEC_NAME.get(curve));
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", provider);
kpg.initialize(gps);
// Generate dummy keypair to get parameter spec.
KeyPair apair = kpg.generateKeyPair();
ECPublicKey apub = (ECPublicKey) apair.getPublic();
ECParameterSpec aspec = apub.getParams();
EllipticCurve acurve = aspec.getCurve();
// Matches the parameter spec
if (acurve.equals(crv)) {
return curve;
}
}
// Did not find a supported curve.
throw new NoSuchAlgorithmException("Curve not supported.");
} catch (GeneralSecurityException e) {
throw new IllegalStateException(e);
}
}
代码示例来源:origin: com.google.crypto.tink/tink
/** Checks that the public key's params spec is the same as the private key's params spec. */
static void validatePublicKeySpec(ECPublicKey publicKey, ECPrivateKey privateKey)
throws GeneralSecurityException {
try {
ECParameterSpec publicKeySpec = publicKey.getParams();
ECParameterSpec privateKeySpec = privateKey.getParams();
if (!publicKeySpec.getCurve().equals(privateKeySpec.getCurve())
|| !publicKeySpec.getGenerator().equals(privateKeySpec.getGenerator())
|| !publicKeySpec.getOrder().equals(privateKeySpec.getOrder())
|| publicKeySpec.getCofactor() != privateKeySpec.getCofactor()) {
throw new GeneralSecurityException("invalid public key spec");
}
} catch (IllegalArgumentException | NullPointerException ex) {
// The Java security providers on Android K and Android L might throw these unchecked
// exceptions, converting them to a checked one to not crash the JVM.
throw new GeneralSecurityException(ex.toString());
}
}
代码示例来源:origin: org.conscrypt/conscrypt-openjdk
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o instanceof OpenSSLECPrivateKey) {
OpenSSLECPrivateKey other = (OpenSSLECPrivateKey) o;
return key.equals(other.key);
}
if (!(o instanceof ECPrivateKey)) {
return false;
}
final ECPrivateKey other = (ECPrivateKey) o;
if (!getPrivateKey().equals(other.getS())) {
return false;
}
final ECParameterSpec spec = getParams();
final ECParameterSpec otherSpec = other.getParams();
return spec.getCurve().equals(otherSpec.getCurve())
&& spec.getGenerator().equals(otherSpec.getGenerator())
&& spec.getOrder().equals(otherSpec.getOrder())
&& spec.getCofactor() == otherSpec.getCofactor();
}
代码示例来源:origin: com.bugvm/bugvm-rt
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o instanceof OpenSSLECPrivateKey) {
OpenSSLECPrivateKey other = (OpenSSLECPrivateKey) o;
return key.equals(other.key);
}
if (!(o instanceof ECPrivateKey)) {
return false;
}
final ECPrivateKey other = (ECPrivateKey) o;
if (!getPrivateKey().equals(other.getS())) {
return false;
}
final ECParameterSpec spec = getParams();
final ECParameterSpec otherSpec = other.getParams();
return spec.getCurve().equals(otherSpec.getCurve())
&& spec.getGenerator().equals(otherSpec.getGenerator())
&& spec.getOrder().equals(otherSpec.getOrder())
&& spec.getCofactor() == otherSpec.getCofactor();
}
代码示例来源:origin: ibinti/bugvm
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o instanceof OpenSSLECPrivateKey) {
OpenSSLECPrivateKey other = (OpenSSLECPrivateKey) o;
return key.equals(other.key);
}
if (!(o instanceof ECPrivateKey)) {
return false;
}
final ECPrivateKey other = (ECPrivateKey) o;
if (!getPrivateKey().equals(other.getS())) {
return false;
}
final ECParameterSpec spec = getParams();
final ECParameterSpec otherSpec = other.getParams();
return spec.getCurve().equals(otherSpec.getCurve())
&& spec.getGenerator().equals(otherSpec.getGenerator())
&& spec.getOrder().equals(otherSpec.getOrder())
&& spec.getCofactor() == otherSpec.getCofactor();
}
代码示例来源:origin: org.apache.santuario/xmlsec
private static boolean matchCurve(ECParameterSpec params, Curve curve) {
int fieldSize = params.getCurve().getField().getFieldSize();
if (curve.getCurve().getField().getFieldSize() == fieldSize
&& curve.getCurve().equals(params.getCurve())
&& curve.getGenerator().equals(params.getGenerator())
&& curve.getOrder().equals(params.getOrder())
&& curve.getCofactor() == params.getCofactor()) {
return true;
} else {
return false;
}
}
代码示例来源:origin: org.conscrypt/conscrypt-openjdk-uber
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o instanceof OpenSSLECPrivateKey) {
OpenSSLECPrivateKey other = (OpenSSLECPrivateKey) o;
return key.equals(other.key);
}
if (!(o instanceof ECPrivateKey)) {
return false;
}
final ECPrivateKey other = (ECPrivateKey) o;
if (!getPrivateKey().equals(other.getS())) {
return false;
}
final ECParameterSpec spec = getParams();
final ECParameterSpec otherSpec = other.getParams();
return spec.getCurve().equals(otherSpec.getCurve())
&& spec.getGenerator().equals(otherSpec.getGenerator())
&& spec.getOrder().equals(otherSpec.getOrder())
&& spec.getCofactor() == otherSpec.getCofactor();
}
代码示例来源:origin: com.nimbusds/nimbus-jose-jwt
private static void validateEcCurves(ECPublicKey publicKey, ECPrivateKey privateKey) throws JOSEException {
final ECParameterSpec pubParams = publicKey.getParams();
final ECParameterSpec privParams = privateKey.getParams();
if (!pubParams.getCurve().equals(privParams.getCurve())) {
throw new JOSEException("Public/private EC key curve mismatch: " + publicKey);
}
if (pubParams.getCofactor() != privParams.getCofactor()) {
throw new JOSEException("Public/private EC key cofactor mismatch: " + publicKey);
}
if (!pubParams.getGenerator().equals(privParams.getGenerator())) {
throw new JOSEException("Public/private EC key generator mismatch: " + publicKey);
}
if (!pubParams.getOrder().equals(privParams.getOrder())) {
throw new JOSEException("Public/private EC key order mismatch: " + publicKey);
}
}
代码示例来源:origin: ibinti/bugvm
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o instanceof OpenSSLECPrivateKey) {
OpenSSLECPrivateKey other = (OpenSSLECPrivateKey) o;
return key.equals(other.key);
}
if (!(o instanceof ECPublicKey)) {
return false;
}
final ECPublicKey other = (ECPublicKey) o;
if (!getPublicKey().equals(other.getW())) {
return false;
}
final ECParameterSpec spec = getParams();
final ECParameterSpec otherSpec = other.getParams();
return spec.getCurve().equals(otherSpec.getCurve())
&& spec.getGenerator().equals(otherSpec.getGenerator())
&& spec.getOrder().equals(otherSpec.getOrder())
&& spec.getCofactor() == otherSpec.getCofactor();
}
代码示例来源:origin: org.conscrypt/conscrypt-openjdk-uber
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o instanceof OpenSSLECPublicKey) {
OpenSSLECPublicKey other = (OpenSSLECPublicKey) o;
return key.equals(other.key);
}
if (!(o instanceof ECPublicKey)) {
return false;
}
final ECPublicKey other = (ECPublicKey) o;
if (!getPublicKey().equals(other.getW())) {
return false;
}
final ECParameterSpec spec = getParams();
final ECParameterSpec otherSpec = other.getParams();
return spec.getCurve().equals(otherSpec.getCurve())
&& spec.getGenerator().equals(otherSpec.getGenerator())
&& spec.getOrder().equals(otherSpec.getOrder())
&& spec.getCofactor() == otherSpec.getCofactor();
}
代码示例来源:origin: com.bugvm/bugvm-rt
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o instanceof OpenSSLECPrivateKey) {
OpenSSLECPrivateKey other = (OpenSSLECPrivateKey) o;
return key.equals(other.key);
}
if (!(o instanceof ECPublicKey)) {
return false;
}
final ECPublicKey other = (ECPublicKey) o;
if (!getPublicKey().equals(other.getW())) {
return false;
}
final ECParameterSpec spec = getParams();
final ECParameterSpec otherSpec = other.getParams();
return spec.getCurve().equals(otherSpec.getCurve())
&& spec.getGenerator().equals(otherSpec.getGenerator())
&& spec.getOrder().equals(otherSpec.getOrder())
&& spec.getCofactor() == otherSpec.getCofactor();
}
代码示例来源:origin: org.conscrypt/conscrypt-openjdk
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o instanceof OpenSSLECPublicKey) {
OpenSSLECPublicKey other = (OpenSSLECPublicKey) o;
return key.equals(other.key);
}
if (!(o instanceof ECPublicKey)) {
return false;
}
final ECPublicKey other = (ECPublicKey) o;
if (!getPublicKey().equals(other.getW())) {
return false;
}
final ECParameterSpec spec = getParams();
final ECParameterSpec otherSpec = other.getParams();
return spec.getCurve().equals(otherSpec.getCurve())
&& spec.getGenerator().equals(otherSpec.getGenerator())
&& spec.getOrder().equals(otherSpec.getOrder())
&& spec.getCofactor() == otherSpec.getCofactor();
}
内容来源于网络,如有侵权,请联系作者删除!