source: fedd/abac-src/rtml/src/edu/stanford/rt/datatype/KeyValue.java @ 8780cbec

axis_examplecompt_changesinfo-opsversion-1.30version-2.00version-3.01version-3.02
Last change on this file since 8780cbec was 8780cbec, checked in by Jay Jacobs <Jay.Jacobs@…>, 15 years ago

ABAC sources from Cobham

  • Property mode set to 100644
File size: 2.7 KB
Line 
1package edu.stanford.rt.datatype;
2
3import java.security.PublicKey;
4import java.security.KeyFactory;
5import java.security.NoSuchAlgorithmException;
6
7import java.security.spec.DSAPublicKeySpec;
8import java.security.spec.RSAPublicKeySpec;
9import java.security.spec.InvalidKeySpecException;
10
11import java.security.interfaces.DSAPublicKey;
12import java.security.interfaces.RSAPublicKey;
13
14/**
15 * @author Ninghui Li, Sandra Qiu <br>
16 *
17 *  Note: This class is not useable.
18 */
19public class KeyValue implements DataValue
20{
21    private KeyType type;
22   
23    private PublicKey value;
24   
25    public KeyValue(KeyType type, PublicKey value)
26    {
27        this.type = type;
28        this.value = value;
29    }
30
31    public KeyType getType()
32    {
33        return type;
34    }
35       
36    public PublicKey getValue()
37    {
38        return value;
39    }
40
41    public String toString()
42    {
43        KeyFactory kf = null;
44        StringBuffer sb = new StringBuffer();
45
46        if(value instanceof DSAPublicKey)
47        {
48            try
49            {
50                kf = KeyFactory.getInstance("DSA");
51                DSAPublicKeySpec dsaPubKeySpec = 
52                    (DSAPublicKeySpec)kf.getKeySpec(value, DSAPublicKeySpec.class);
53                sb.append("DSA Public Key: \n")
54                    .append("\nG = ").append(dsaPubKeySpec.getG())
55                    .append("\nP = ").append(dsaPubKeySpec.getP())
56                    .append("\nQ = ").append(dsaPubKeySpec.getQ())
57                    .append("\nY = ").append(dsaPubKeySpec.getY());
58            } 
59            catch(NoSuchAlgorithmException e1)
60            {
61                e1.printStackTrace();
62            }
63            catch(InvalidKeySpecException e2)
64            {
65                e2.printStackTrace();
66            }
67        }
68        else if(value instanceof RSAPublicKey)
69        {
70            try
71            {
72                kf = KeyFactory.getInstance("RSA");
73                RSAPublicKeySpec rsaPubKeySpec = 
74                    (RSAPublicKeySpec)kf.getKeySpec(value, RSAPublicKeySpec.class);
75                sb.append("DSA Public Key: \n")
76                    .append("\nModulus = ").append(rsaPubKeySpec.getModulus())
77                    .append("\nExponent = ").append(rsaPubKeySpec.getPublicExponent());
78            } 
79            catch(NoSuchAlgorithmException e1)
80            {
81                e1.printStackTrace();
82            }
83            catch(InvalidKeySpecException e2)
84            {
85                e2.printStackTrace();
86            }
87        }
88        else
89        {
90            // TODO: any
91        }
92       
93        return sb.toString();
94    }
95   
96}
Note: See TracBrowser for help on using the repository browser.