01: /*
02: * SRAPBEImpl.java
03: *
04: * Created on January 27, 2003, 12:50 PM
05: */
06:
07: /**
08: *
09: * @author ss133690
10: * @version
11: */package com.sun.portal.cli.cert;
12:
13: import java.security.*;
14: import com.sun.portal.log.common.PortalLogger;
15: import javax.crypto.spec.*;
16: import javax.crypto.*;
17:
18: public class SRAPBEImpl extends SRADecoder implements
19: PBEPasswordContext {
20:
21: private String certdir;
22: private static final String SECURE_PASS_DERIVATOR = "spd";
23:
24: static {
25: System.loadLibrary(SECURE_PASS_DERIVATOR);
26: }
27:
28: public SRAPBEImpl(String certdir) {
29: this .certdir = certdir;
30: }
31:
32: public void init() throws SRADecoderException {
33: decoderCntx = getDecoderContext();
34: try {
35: Security.insertProviderAt(decoderCntx.getDefaultProvider(),
36: 1);
37: Security.insertProviderAt(decoderCntx.getProvider(), 2);
38: paramSpec = new PBEParameterSpec(decoderCntx.getSalt(), 20);
39: PBEKeySpec keySpec = new PBEKeySpec(getPassword()
40: .toCharArray());
41: SecretKeyFactory kf = SecretKeyFactory.getInstance(
42: decoderCntx.getSecretKeyAlgorithm(), decoderCntx
43: .getProvider().getName());
44: secretKey = kf.generateSecret(keySpec);
45: cipher = Cipher.getInstance(decoderCntx.getEncAlgorithm(),
46: decoderCntx.getProvider().getName());
47: digest = MessageDigest.getInstance(decoderCntx
48: .getDigestAlgorithm(), decoderCntx
49: .getDefaultProvider().getName());
50: } catch (Exception ex) {
51: throw new SRADecoderException(ex.toString());
52: }
53: }
54:
55: protected SRADecoderContext getDecoderContext() {
56: if (decoderCntx != null)
57: return decoderCntx;
58: else
59: return new SRADecoderContextImpl();
60: }
61:
62: public String getPassword() {
63: try {
64: return getEncodedStr(getPasswd(certdir));
65: } catch (Exception ex) {
66: return null;
67: }
68: }
69:
70: private native byte[] getPasswd(String certdir) throws Exception;
71:
72: }
|