Java Code Examples for org.bouncycastle.jce.spec.ECNamedCurveParameterSpec#getH()
The following examples show how to use
org.bouncycastle.jce.spec.ECNamedCurveParameterSpec#getH() .
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: SoftKeymasterBlob.java From keystore-decryptor with Apache License 2.0 | 7 votes |
private static ECPrivateKey toJcaPrivateKey(org.bouncycastle.asn1.sec.ECPrivateKey ecPrivateKey) throws GeneralSecurityException { String curveName = null; ASN1ObjectIdentifier curveId = (ASN1ObjectIdentifier) ecPrivateKey.getParameters(); if (curveId.equals(secp224r1_OID)) { curveName = "secp224r1"; } else if (curveId.equals(prime256v1_OID)) { curveName = "prime256v1"; } else if (curveId.equals(secp384r1_OID)) { curveName = "secp384r1"; } else if (curveId.equals(secp521r1_OID)) { curveName = "secp521r1"; } else { throw new IllegalStateException("Unknown curve OID: " + curveId); } ECNamedCurveParameterSpec sp = ECNamedCurveTable.getParameterSpec(curveName); ECParameterSpec params = new ECNamedCurveSpec(sp.getName(), sp.getCurve(), sp.getG(), sp.getN(), sp.getH()); ECPrivateKeySpec pkSpec = new ECPrivateKeySpec(ecPrivateKey.getKey(), params); KeyFactory kf = KeyFactory.getInstance("EC"); ECPrivateKey privateKey = (ECPrivateKey) kf.generatePrivate(pkSpec); return privateKey; }
Example 2
Source File: LocalIdentity.java From ts3j with Apache License 2.0 | 6 votes |
/** * Generates a new identity with a given security level target. * @param securityLevel security level to generate for (may take time) * @return local identity with given security level * @throws GeneralSecurityException */ public static LocalIdentity generateNew(int securityLevel) throws GeneralSecurityException { ECNamedCurveParameterSpec ecp = ECNamedCurveTable.getParameterSpec("prime256v1"); ECDomainParameters domainParams = new ECDomainParameters(ecp.getCurve(), ecp.getG(), ecp.getN(), ecp.getH(), ecp.getSeed()); ECKeyGenerationParameters keyGenParams = new ECKeyGenerationParameters(domainParams, new SecureRandom()); ECKeyPairGenerator generator = new ECKeyPairGenerator(); generator.init(keyGenParams); AsymmetricCipherKeyPair keyPair = generator.generateKeyPair(); ECPrivateKeyParameters privateKey = (ECPrivateKeyParameters) keyPair.getPrivate(); ECPublicKeyParameters publicKey = (ECPublicKeyParameters) keyPair.getPublic(); LocalIdentity localIdentity = load(publicKey.getQ().normalize(), privateKey.getD()); localIdentity.improveSecurity(securityLevel); return localIdentity; }
Example 3
Source File: Crypto.java From webauthndemo with Apache License 2.0 | 5 votes |
public static PublicKey getECPublicKey(java.security.spec.ECPoint w, String stdCurveName) throws NoSuchAlgorithmException, InvalidKeySpecException { ECNamedCurveParameterSpec parameterSpec = ECNamedCurveTable.getParameterSpec(stdCurveName); java.security.spec.ECParameterSpec params = new ECNamedCurveSpec(parameterSpec.getName(), parameterSpec.getCurve(), parameterSpec.getG(), parameterSpec.getN(), parameterSpec.getH(), parameterSpec.getSeed()); KeySpec keySpec = new java.security.spec.ECPublicKeySpec(w, params); KeyFactory keyFactory = KeyFactory.getInstance("EC"); return keyFactory.generatePublic(keySpec); }
Example 4
Source File: Ts3Crypt.java From ts3j with Apache License 2.0 | 4 votes |
private static ECDomainParameters getDomainParameters() { ECNamedCurveParameterSpec ecp = ECNamedCurveTable.getParameterSpec("prime256v1"); return new ECDomainParameters(ecp.getCurve(), ecp.getG(), ecp.getN(), ecp.getH(), ecp.getSeed()); }
Example 5
Source File: ECGEN.java From warp10-platform with Apache License 2.0 | 2 votes |
@Override public Object apply(WarpScriptStack stack) throws WarpScriptException { Object top = stack.pop(); if (!(top instanceof String)) { throw new WarpScriptException(getName() + " expects a curve name."); } String name = (String) top; ECKeyPairGenerator gen = new ECKeyPairGenerator(); ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec(name); if (null == spec) { throw new WarpScriptException(getName() + " only supports the following curves: " + getCurves() + "."); } ECCurve curve = spec.getCurve(); ECDomainParameters domainParams = new ECDomainParameters(curve, spec.getG(),spec.getN(), spec.getH(), spec.getSeed()); ECKeyGenerationParameters params = new ECKeyGenerationParameters(domainParams, CryptoHelper.getSecureRandom()); gen.init(params); final AsymmetricCipherKeyPair keypair = gen.generateKeyPair(); ECPrivateKeyParameters privateKey = (ECPrivateKeyParameters) keypair.getPrivate(); ECPublicKeyParameters publicKey = (ECPublicKeyParameters) keypair.getPublic(); Map<String,String> keyparams = new HashMap<String,String>(); keyparams.put(Constants.KEY_CURVE, name); keyparams.put(Constants.KEY_D, privateKey.getD().toString()); stack.push(keyparams); keyparams = new HashMap<String,String>(); keyparams.put(Constants.KEY_CURVE, name); keyparams.put(Constants.KEY_Q, Hex.encodeHexString(publicKey.getQ().getEncoded())); stack.push(keyparams); return stack; }