2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package java.security;
21 * {@link Signer} represents an identity (individual or corporation) that owns a
22 * private key and the corresponding public key.
24 * @deprecated Replaced by behavior in {@link java.security.cert
25 * java.security.cert} package and {@link java.security.Principal
29 public abstract class Signer extends Identity {
31 private static final long serialVersionUID = -1763464102261361480L;
33 private PrivateKey privateKey;
36 * Constructs a new instance of {@code Signer}.
43 * Constructs a new instance of {@code Signer} with the given name.
46 * the name of the signer.
48 public Signer(String name) {
53 * Constructs a new instance of {@code Signer} with the given name in the
57 * the name of the signer.
59 * the scope of the signer.
60 * @throws KeyManagementException
61 * if a signer with the specified name already exists in the
64 public Signer(String name, IdentityScope scope)
65 throws KeyManagementException {
70 * Returns the private key of this {@code Signer}. If a {@code
71 * SecurityManager} is installed, code calling this method needs the {@code
72 * SecurityPermission} {@code "getSignerPrivateKey"} to be granted, otherwise
73 * a {@code SecurityException} will be thrown.
75 * @return the private key of this {@code Signer}.
76 * @throws SecurityException
77 * if a {@code SecurityManager} is installed and the caller does
78 * not have permission to invoke this method.
80 public PrivateKey getPrivateKey() {
81 SecurityManager sm = System.getSecurityManager();
83 sm.checkSecurityAccess("getSignerPrivateKey");
90 * Associates the specified key pair with this {@code Signer}. If a {@code
91 * SecurityManager} is installed, code calling this method needs the {@code
92 * SecurityPermission} {@code getSignerPrivateKey} to be granted, otherwise
93 * a {@code SecurityException} will be thrown.
96 * the key pair to associate with this {@code Signer}.
97 * @throws InvalidParameterException
98 * if the key pair is invalid.
99 * @throws KeyException
100 * if any other key related problem occurs.
101 * @throws SecurityException
102 * if a {@code SecurityManager} is installed and the caller does
103 * not have permission to invoke this method.
105 public final void setKeyPair(KeyPair pair)
106 throws InvalidParameterException, KeyException {
109 throw new NullPointerException();
112 if ((pair.getPrivate() == null) || (pair.getPublic() == null)) {
113 throw new InvalidParameterException();
115 SecurityManager sm = System.getSecurityManager();
117 sm.checkSecurityAccess("setSignerKeyPair");
119 final PublicKey pk = pair.getPublic();
121 AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
122 public Void run() throws KeyManagementException {
127 } catch (PrivilegedActionException e) {
128 throw new KeyException(e.getException());
130 this.privateKey = pair.getPrivate();
134 * Returns a string containing a concise, human-readable description of this
135 * {@code Signer} including its name and its scope if present.
137 * @return a printable representation for this {@code Signer}.
140 public String toString() {
141 String s = "[Signer]" + getName();
142 if (getScope() != null) {
143 s = s + '[' + getScope().toString() + ']';