1 7 8 package java.security; 9 10 import java.io.*; 11 12 30 @Deprecated 31 public abstract class Signer extends Identity { 32 33 private static final long serialVersionUID = -1763464102261361480L; 34 35 40 private PrivateKey privateKey; 41 42 46 protected Signer() { 47 super(); 48 } 49 50 51 56 public Signer(String name) { 57 super(name); 58 } 59 60 70 public Signer(String name, IdentityScope scope) 71 throws KeyManagementException { 72 super(name, scope); 73 } 74 75 91 public PrivateKey getPrivateKey() { 92 check("getSignerPrivateKey"); 93 return privateKey; 94 } 95 96 115 public final void setKeyPair(KeyPair pair) 116 throws InvalidParameterException , KeyException { 117 check("setSignerKeyPair"); 118 final PublicKey pub = pair.getPublic(); 119 PrivateKey priv = pair.getPrivate(); 120 121 if (pub == null || priv == null) { 122 throw new InvalidParameterException (); 123 } 124 try { 125 AccessController.doPrivileged(new PrivilegedExceptionAction () { 126 public Object run() throws KeyManagementException { 127 setPublicKey(pub); 128 return null; 129 } 130 }); 131 } catch (PrivilegedActionException pae) { 132 throw (KeyManagementException ) pae.getException(); 133 } 134 privateKey = priv; 135 } 136 137 String printKeys() { 138 String keys = ""; 139 PublicKey publicKey = getPublicKey(); 140 if (publicKey != null && privateKey != null) { 141 keys = "\tpublic and private keys initialized"; 142 143 } else { 144 keys = "\tno keys"; 145 } 146 return keys; 147 } 148 149 154 public String toString() { 155 return "[Signer]" + super.toString(); 156 } 157 158 private static void check(String directive) { 159 SecurityManager security = System.getSecurityManager(); 160 if (security != null) { 161 security.checkSecurityAccess(directive); 162 } 163 } 164 165 } 166 167 | Popular Tags |