source: other-projects/trunk/gs3-release-maker/tasks/sshtaskdef/src/mindbright/ssh/SSHRSAPublicKeyString.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 2.3 KB
Line 
1/******************************************************************************
2 *
3 * Copyright (c) 1998,99 by Mindbright Technology AB, Stockholm, Sweden.
4 * www.mindbright.se, [email protected]
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 *****************************************************************************
17 * $Author: mats $
18 * $Date: 1999/01/25 21:15:07 $
19 * $Name: rel1-2-1 $
20 *****************************************************************************/
21package mindbright.ssh;
22
23import java.math.BigInteger;
24import java.util.StringTokenizer;
25import java.util.NoSuchElementException;
26import java.io.*;
27
28import mindbright.security.*;
29
30public class SSHRSAPublicKeyString extends RSAPublicKey {
31
32 String user;
33 String opts;
34
35 public SSHRSAPublicKeyString(String opts, String user, BigInteger e, BigInteger n) {
36 super(e, n);
37 this.opts = opts;
38 this.user = user;
39 }
40
41 public static SSHRSAPublicKeyString createKey(String opts, String pubKey) throws NoSuchElementException {
42 StringTokenizer tok = new StringTokenizer(pubKey);
43 String user = null;
44 String bits;
45 String e;
46 String n;
47
48 bits = tok.nextToken();
49 e = tok.nextToken();
50 n = tok.nextToken();
51 if(tok.hasMoreElements())
52 user = tok.nextToken();
53
54 return new SSHRSAPublicKeyString(opts, user, new BigInteger(e), new BigInteger(n));
55 }
56
57 public String getOpts() {
58 return opts;
59 }
60
61 public String getUser() {
62 return user;
63 }
64
65 public String toString() {
66 return ((opts != null ? (opts + " ") : "") +
67 bitLength() + " " + getE() + " " + getN() + " " +
68 (user != null ? user : ""));
69 }
70
71 public void toFile(String fileName) throws IOException {
72 FileOutputStream fileOut = new FileOutputStream(fileName);
73 SSHDataOutputStream dataOut = new SSHDataOutputStream(fileOut);
74 dataOut.writeBytes(toString());
75 dataOut.close();
76 }
77
78}
Note: See TracBrowser for help on using the repository browser.