001/* 002 * Copyright 2021 Emmanuel Bourg 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package net.jsign.jca; 018 019import java.security.PrivateKey; 020import java.util.HashMap; 021import java.util.Map; 022 023/** 024 * Reference to a private key held by the signing service. 025 * 026 * @since 4.0 027 */ 028public class SigningServicePrivateKey implements PrivateKey { 029 030 /** The signing service */ 031 private SigningService service; 032 033 /** The identifier of the key */ 034 private final String id; 035 036 /** The algorithm of the key (for example RSA or ECDSA) */ 037 private final String algorithm; 038 039 /** Extra properties of the key */ 040 private final Map<String, Object> properties = new HashMap<>(); 041 042 /** 043 * Creates a new reference to a privaye key. 044 * 045 * @param id The identifier of the key 046 * @param algorithm The algorithm of the key (RSA or ECDSA) 047 */ 048 @Deprecated 049 public SigningServicePrivateKey(String id, String algorithm) { 050 this.id = id; 051 this.algorithm = algorithm; 052 } 053 054 /** 055 * Creates a new reference to a privaye key. 056 * 057 * @param id The identifier of the key 058 * @param algorithm The algorithm of the key (RSA or ECDSA) 059 * @param service The signing service 060 */ 061 SigningServicePrivateKey(String id, String algorithm, SigningService service) { 062 this(id, algorithm); 063 this.service = service; 064 } 065 066 public String getId() { 067 return id; 068 } 069 070 public Map<String, Object> getProperties() { 071 return properties; 072 } 073 074 SigningService getService() { 075 return service; 076 } 077 078 @Override 079 public String getAlgorithm() { 080 return algorithm; 081 } 082 083 @Override 084 public String getFormat() { 085 throw new UnsupportedOperationException(); 086 } 087 088 @Override 089 public byte[] getEncoded() { 090 throw new UnsupportedOperationException(); 091 } 092}