1 19 20 package com.sslexplorer.security.pki; 21 22 27 public abstract class SshKeyPair { 28 private SshPrivateKey prv; 29 private SshPublicKey pub; 30 31 34 public SshKeyPair() { 35 } 36 37 42 public abstract void generate(int bits); 43 44 49 public void setPrivateKey(SshPrivateKey key) { 50 this.prv = key; 51 this.pub = key.getPublicKey(); 52 } 53 54 63 public SshPrivateKey setPrivateKey(byte[] encoded) 64 throws InvalidKeyException { 65 setPrivateKey(decodePrivateKey(encoded)); 66 67 return this.prv; 68 } 69 70 75 public SshPrivateKey getPrivateKey() { 76 return prv; 77 } 78 79 88 public SshPublicKey setPublicKey(byte[] encoded) 89 throws InvalidKeyException { 90 this.pub = decodePublicKey(encoded); 91 this.prv = null; 92 93 return this.pub; 94 } 95 96 101 public SshPublicKey getPublicKey() { 102 return pub; 103 } 104 105 114 public abstract SshPrivateKey decodePrivateKey(byte[] encoded) 115 throws InvalidKeyException; 116 117 126 public abstract SshPublicKey decodePublicKey(byte[] encoded) 127 throws InvalidKeyException; 128 } 129 | Popular Tags |