private KeyManager<PublicKeySign> publicKeySignKeyManager(String typeUrl) throws GeneralSecurityException { switch (typeUrl) { case EcdsaSignKeyManager.TYPE_URL: return new EcdsaSignKeyManager(); case Ed25519PrivateKeyManager.TYPE_URL: return new Ed25519PrivateKeyManager(); default: throw new GeneralSecurityException( String.format("No support for primitive 'PublicKeySign' with key type '%s'.", typeUrl)); } } }
/** @param serializedKey serialized {@code EcdsaPrivateKey} proto */ @Override public PublicKeySign getPrimitive(ByteString serializedKey) throws GeneralSecurityException { try { EcdsaPrivateKey privKeyProto = EcdsaPrivateKey.parseFrom(serializedKey); return getPrimitive(privKeyProto); } catch (InvalidProtocolBufferException e) { throw new GeneralSecurityException("expected serialized EcdsaPrivateKey proto", e); } }
/** * @param serializedKeyFormat serialized {@code EcdsaKeyFormat} proto * @return new {@code EcdsaPrivateKey} proto */ @Override public MessageLite newKey(ByteString serializedKeyFormat) throws GeneralSecurityException { try { EcdsaKeyFormat ecdsaKeyFormat = EcdsaKeyFormat.parseFrom(serializedKeyFormat); return newKey(ecdsaKeyFormat); } catch (InvalidProtocolBufferException e) { throw new GeneralSecurityException("expected EcdsaKeyFormat proto", e); } }
/** @param key {@code EcdsaPrivateKey} proto */ @Override public PublicKeySign getPrimitive(MessageLite key) throws GeneralSecurityException { if (!(key instanceof EcdsaPrivateKey)) { throw new GeneralSecurityException("expected EcdsaPrivateKey proto"); } EcdsaPrivateKey keyProto = (EcdsaPrivateKey) key; validateKey(keyProto); ECPrivateKey privateKey = EllipticCurves.getEcPrivateKey( SigUtil.toCurveType(keyProto.getPublicKey().getParams().getCurve()), keyProto.getKeyValue().toByteArray()); return new EcdsaSignJce( privateKey, SigUtil.toHashType(keyProto.getPublicKey().getParams().getHashType()), SigUtil.toEcdsaEncoding(keyProto.getPublicKey().getParams().getEncoding())); }
/** * @param serializedKeyFormat serialized {@code EcdsaKeyFormat} proto * @return {@code KeyData} with a new {@code EcdsaPrivateKey} proto */ @Override public KeyData newKeyData(ByteString serializedKeyFormat) throws GeneralSecurityException { EcdsaPrivateKey key = (EcdsaPrivateKey) newKey(serializedKeyFormat); return KeyData.newBuilder() .setTypeUrl(TYPE_URL) .setValue(key.toByteString()) .setKeyMaterialType(KeyData.KeyMaterialType.ASYMMETRIC_PRIVATE) .build(); }