1 19 20 package com.sslexplorer.security.pki.rsa; 21 22 23 import java.security.KeyPair ; 24 import java.security.KeyPairGenerator ; 25 import java.security.NoSuchAlgorithmException ; 26 import java.security.interfaces.RSAPrivateKey ; 27 import java.security.interfaces.RSAPublicKey ; 28 29 import com.sslexplorer.security.pki.InvalidKeyException; 30 import com.sslexplorer.security.pki.SshKeyPair; 31 import com.sslexplorer.security.pki.SshPrivateKey; 32 import com.sslexplorer.security.pki.SshPublicKey; 33 import com.sslexplorer.security.pki.Utils; 34 35 36 41 public class SshRsaKeyPair extends SshKeyPair { 42 private RSAPrivateKey prvKey; 43 private RSAPublicKey pubKey; 44 45 48 public SshRsaKeyPair() { 49 } 50 51 60 public SshPrivateKey decodePrivateKey(byte[] encoded) 61 throws InvalidKeyException { 62 return new SshRsaPrivateKey(encoded); 63 } 64 65 74 public SshPublicKey decodePublicKey(byte[] encoded) 75 throws InvalidKeyException { 76 return new SshRsaPublicKey(encoded); 77 } 78 79 84 public void generate(int bits) { 85 try { 86 KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); 88 keyGen.initialize(bits, Utils.getRND()); 89 90 KeyPair pair = keyGen.generateKeyPair(); 91 92 setPrivateKey(new SshRsaPrivateKey( 94 (RSAPrivateKey ) pair.getPrivate(), 95 (RSAPublicKey ) pair.getPublic())); 96 } catch (NoSuchAlgorithmException nsae) { 97 prvKey = null; 98 pubKey = null; 99 } 100 } 101 } 102 | Popular Tags |