KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > security > pki > SECSHPublicKeyFormat


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.security.pki;
21
22
23 /**
24  *
25  *
26  * @author $author$
27  */

28 public class SECSHPublicKeyFormat extends Base64EncodedFileFormat
29     implements SshPublicKeyFormat {
30     private static String JavaDoc BEGIN = "---- BEGIN SSH2 PUBLIC KEY ----";
31     private static String JavaDoc END = "---- END SSH2 PUBLIC KEY ----";
32
33     /**
34      * Creates a new SECSHPublicKeyFormat object.
35      *
36      * @param subject
37      * @param comment
38      */

39     public SECSHPublicKeyFormat(String JavaDoc subject, String JavaDoc comment) {
40         super(BEGIN, END);
41         setHeaderValue("Subject", subject);
42         setComment(comment);
43     }
44
45     /**
46      * Creates a new SECSHPublicKeyFormat object.
47      */

48     public SECSHPublicKeyFormat() {
49         super(BEGIN, END);
50     }
51
52     /**
53      *
54      *
55      * @param comment
56      */

57     public void setComment(String JavaDoc comment) {
58         setHeaderValue("Comment",
59             (comment.trim().startsWith("\"") ? "" : "\"") + comment.trim() +
60             (comment.trim().endsWith("\"") ? "" : "\""));
61     }
62
63     /**
64      *
65      *
66      * @return
67      */

68     public String JavaDoc getComment() {
69         return getHeaderValue("Comment");
70     }
71
72     /**
73      *
74      *
75      * @return
76      */

77     public String JavaDoc getFormatType() {
78         return "SECSH-PublicKey-" + super.getFormatType();
79     }
80
81     /**
82      *
83      *
84      * @param algorithm
85      *
86      * @return
87      */

88     public boolean supportsAlgorithm(String JavaDoc algorithm) {
89         return SshKeyPairFactory.supportsKey(algorithm);
90     }
91 }
92
Popular Tags