1 /* |
1 /* |
2 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
65 |
65 |
66 private BigInteger s; // private value |
66 private BigInteger s; // private value |
67 private ECParameterSpec params; |
67 private ECParameterSpec params; |
68 |
68 |
69 /** |
69 /** |
70 * Construct a key from its encoding. Called by the ECKeyFactory and |
70 * Construct a key from its encoding. Called by the ECKeyFactory. |
71 * the SunPKCS11 code. |
|
72 */ |
71 */ |
73 public ECPrivateKeyImpl(byte[] encoded) throws InvalidKeyException { |
72 ECPrivateKeyImpl(byte[] encoded) throws InvalidKeyException { |
74 decode(encoded); |
73 decode(encoded); |
75 } |
74 } |
76 |
75 |
77 /** |
76 /** |
78 * Construct a key from its components. Used by the |
77 * Construct a key from its components. Used by the |
79 * KeyFactory and the SunPKCS11 code. |
78 * KeyFactory. |
80 */ |
79 */ |
81 public ECPrivateKeyImpl(BigInteger s, ECParameterSpec params) |
80 ECPrivateKeyImpl(BigInteger s, ECParameterSpec params) |
82 throws InvalidKeyException { |
81 throws InvalidKeyException { |
83 this.s = s; |
82 this.s = s; |
84 this.params = params; |
83 this.params = params; |
85 // generate the encoding |
84 // generate the encoding |
86 algid = new AlgorithmId |
85 algid = new AlgorithmId |
87 (AlgorithmId.EC_oid, ECParameters.getAlgorithmParameters(params)); |
86 (AlgorithmId.EC_oid, ECParameters.getAlgorithmParameters(params)); |
88 try { |
87 try { |
89 DerOutputStream out = new DerOutputStream(); |
88 DerOutputStream out = new DerOutputStream(); |
90 out.putInteger(1); // version 1 |
89 out.putInteger(1); // version 1 |
91 byte[] privBytes = ECParameters.trimZeroes(s.toByteArray()); |
90 byte[] privBytes = ECUtil.trimZeroes(s.toByteArray()); |
92 out.putOctetString(privBytes); |
91 out.putOctetString(privBytes); |
93 DerValue val = |
92 DerValue val = |
94 new DerValue(DerValue.tag_Sequence, out.toByteArray()); |
93 new DerValue(DerValue.tag_Sequence, out.toByteArray()); |
95 key = val.toByteArray(); |
94 key = val.toByteArray(); |
96 } catch (IOException exc) { |
95 } catch (IOException exc) { |