Java Code Examples for org.bouncycastle.jce.spec.ECParameterSpec#getCurve()
The following examples show how to use
org.bouncycastle.jce.spec.ECParameterSpec#getCurve() .
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: BCECUtil.java From littleca with Apache License 2.0 | 5 votes |
/** * openssl i2d_ECPrivateKey函数生成的DER编码的ecc私钥是:PKCS1标准的、带有EC_GROUP、带有公钥的, * 这个工具函数的主要目的就是为了使Java程序能够“识别”openssl生成的ECC私钥 * * @param encodedKey * @return * @throws NoSuchAlgorithmException * @throws NoSuchProviderException * @throws InvalidKeySpecException */ public static ECPrivateKeyParameters convertPkcs1DerToEcPriKey(byte[] encodedKey) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException { PKCS8EncodedKeySpec peks = new PKCS8EncodedKeySpec(encodedKey); KeyFactory kf = KeyFactory.getInstance(ALGO_NAME_EC, BouncyCastleProvider.PROVIDER_NAME); BCECPrivateKey privateKey = (BCECPrivateKey) kf.generatePrivate(peks); ECParameterSpec ecParameterSpec = privateKey.getParameters(); ECDomainParameters ecDomainParameters = new ECDomainParameters(ecParameterSpec.getCurve(), ecParameterSpec.getG(), ecParameterSpec.getN(), ecParameterSpec.getH()); ECPrivateKeyParameters priKey = new ECPrivateKeyParameters(privateKey.getD(), ecDomainParameters); return priKey; }
Example 2
Source File: Utils.java From org.openhab.ui.habot with Eclipse Public License 1.0 | 5 votes |
/** * Load the public key from a URL-safe base64 encoded string. Takes into * account the different encodings, including point compression. * * @param encodedPublicKey */ public static PublicKey loadPublicKey(String encodedPublicKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException { byte[] decodedPublicKey = base64Decode(encodedPublicKey); KeyFactory keyFactory = KeyFactory.getInstance(ALGORITHM, PROVIDER_NAME); ECParameterSpec parameterSpec = ECNamedCurveTable.getParameterSpec(CURVE); ECCurve curve = parameterSpec.getCurve(); ECPoint point = curve.decodePoint(decodedPublicKey); ECPublicKeySpec pubSpec = new ECPublicKeySpec(point, parameterSpec); return keyFactory.generatePublic(pubSpec); }
Example 3
Source File: Utils.java From webpush-java with MIT License | 5 votes |
/** * Load the public key from a byte array. * * @param decodedPublicKey */ public static PublicKey loadPublicKey(byte[] decodedPublicKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException { KeyFactory keyFactory = KeyFactory.getInstance(ALGORITHM, PROVIDER_NAME); ECParameterSpec parameterSpec = ECNamedCurveTable.getParameterSpec(CURVE); ECCurve curve = parameterSpec.getCurve(); ECPoint point = curve.decodePoint(decodedPublicKey); ECPublicKeySpec pubSpec = new ECPublicKeySpec(point, parameterSpec); return keyFactory.generatePublic(pubSpec); }
Example 4
Source File: KeyUtils.java From aerogear-unifiedpush-server with Apache License 2.0 | 5 votes |
public static PublicKey loadPublicKey(String publicKey) throws NoSuchAlgorithmException, InvalidKeySpecException { byte[] decodedPublicKey = Base64Encoder.decode(publicKey); KeyFactory keyFactory = KeyFactory.getInstance(ALGORITHM, PROVIDER); ECParameterSpec parameterSpec = ECNamedCurveTable.getParameterSpec(CURVE); ECCurve curve = parameterSpec.getCurve(); ECPoint point = curve.decodePoint(decodedPublicKey); ECPublicKeySpec pubSpec = new ECPublicKeySpec(point, parameterSpec); return keyFactory.generatePublic(pubSpec); }
Example 5
Source File: BCECUtil.java From gmhelper with Apache License 2.0 | 4 votes |
public static ECPrivateKeyParameters convertPrivateKeyToParameters(BCECPrivateKey ecPriKey) { ECParameterSpec parameterSpec = ecPriKey.getParameters(); ECDomainParameters domainParameters = new ECDomainParameters(parameterSpec.getCurve(), parameterSpec.getG(), parameterSpec.getN(), parameterSpec.getH()); return new ECPrivateKeyParameters(ecPriKey.getD(), domainParameters); }
Example 6
Source File: BCECUtil.java From gmhelper with Apache License 2.0 | 4 votes |
public static ECPublicKeyParameters convertPublicKeyToParameters(BCECPublicKey ecPubKey) { ECParameterSpec parameterSpec = ecPubKey.getParameters(); ECDomainParameters domainParameters = new ECDomainParameters(parameterSpec.getCurve(), parameterSpec.getG(), parameterSpec.getN(), parameterSpec.getH()); return new ECPublicKeyParameters(ecPubKey.getQ(), domainParameters); }
Example 7
Source File: BCECUtil.java From jiguang-java-client-common with MIT License | 4 votes |
public static ECPrivateKeyParameters convertPrivateKeyToParameters(BCECPrivateKey ecPriKey) { ECParameterSpec parameterSpec = ecPriKey.getParameters(); ECDomainParameters domainParameters = new ECDomainParameters(parameterSpec.getCurve(), parameterSpec.getG(), parameterSpec.getN(), parameterSpec.getH()); return new ECPrivateKeyParameters(ecPriKey.getD(), domainParameters); }
Example 8
Source File: BCECUtil.java From jiguang-java-client-common with MIT License | 4 votes |
public static ECPublicKeyParameters convertPublicKeyToParameters(BCECPublicKey ecPubKey) { ECParameterSpec parameterSpec = ecPubKey.getParameters(); ECDomainParameters domainParameters = new ECDomainParameters(parameterSpec.getCurve(), parameterSpec.getG(), parameterSpec.getN(), parameterSpec.getH()); return new ECPublicKeyParameters(ecPubKey.getQ(), domainParameters); }