# Keystore and importing a private key

Sabine Pham (spham@atos-group.com)
Thu, 22 Apr 1999 10:33:32 +0200

- Messages sorted by: [ date ][ thread ][ subject ][ author ]
- Next message: Jan Luehe: "Re: Keystore and importing a private key"
- Previous message: Bernard Leach: "DSA and Signature"
- Next in thread: Jan Luehe: "Re: Keystore and importing a private key"

    Date: Thu, 22 Apr 1999 10:33:32 +0200

    From: Sabine Pham <spham@atos-group.com>

    To: "java-security@java.Sun.COM" <java-security@java.Sun.COM>

    Subject: Keystore and importing a private key

--------------B4D4F3A98BE9A5B535835BE6
Content-Type: text/plain; charset="us-ascii"
X-Sun-Content-Length: 1523

I would like to import a private key into the Keystore. I have an
exception that I don't really understand :

java.security.KeyStoreException: key is not encoded as
EncryptedPrivateKeyInfo
at
sun.security.provider.JavaKeyStore.engineSetKeyEntry(JavaKeyStore.java:277)

at java.security.KeyStore.setKeyEntry(KeyStore.java:395)
at testKeystore.main(Compiled Code)

I try to insert the private following the code below:

// Insert RH certificat
InputStream inStream = new FileInputStream("RHcert.b64");
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate cert =
(X509Certificate)cf.generateCertificate(inStream);
inStream.close();
store.setCertificateEntry("RH", cert);
System.out.println(cert.toString());

// Insert MusycCA certificat
inStream = new FileInputStream("MusycCAcert.b64");
X509Certificate MusycCAcert =
(X509Certificate)cf.generateCertificate(inStream);
inStream.close();
store.setCertificateEntry("MusycCA", MusycCAcert);
System.out.println(cert.toString());

// Insert private key of RH
inStream = new FileInputStream("RHpk.b64");
DataInputStream dis = new DataInputStream(inStream);
byte[] bytes = new byte[dis.available()];
dis.readFully(bytes);
inStream.close();
java.security.cert.Certificate[] chainCert = {MusycCAcert, cert};
store.setKeyEntry("RHpk", bytes, chainCert);

Where am I wrong?
Thank you very much for your help.

Sabine.

P.S. : I attach with this mail the 2 certificates and the private key.

--------------B4D4F3A98BE9A5B535835BE6
Content-Type: application/x-unknown-content-type-WinZip; name="RHcert.b64"
Content-Transfer-Encoding: base64
Content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LzVTZXltdDZ1RTEw
YjZZd3dKOHh2VzUyNGVYMzR6NzdBPT0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
--------------B4D4F3A98BE9A5B535835BE6
Content-Type: application/x-unknown-content-type-WinZip; name="MusycCAcert.b64"
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename="MusycCAcert.b64"
X-Sun-Content-Length: 953

LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUIyekNDQVlXZ0F3SUJBZ0lGQVBaOEkv
QXdEUVlKS29aSWh2Y05BUUVFQlFBd1p6RWpNQ0VHQ1NxR1NJYjMKRFFFSkFSWVViWFZ6ZVdO
QVlYUnZjeTFuY205MWNDNWpiMjB4RlRBVEJnb0praWFKay9Jc1pBRUJFd1ZOZFhONQpZekVO
TUFzR0ExVUVDaE1FUVhSdmN6RWFNQmdHQTFVRUF4TVJUWFZ6ZVdNZ1kyVnlkR2xtYVdOaGRH
VXdIaGNOCk9UZ3dPVEl6TVRVeU5qUTJXaGNOT1RneE1qSXpNVFV5TmpRMldqQm5NU013SVFZ
SktvWklodmNOQVFrQkZoUnQKZFhONVkwQmhkRzl6TFdkeWIzVndMbU52YlRFVk1CTUdDZ21T
Sm9tVDhpeGtBUUVUQlUxMWMzbGpNUTB3Q3dZRApWUVFLRXdSQmRHOXpNUm93R0FZRFZRUURF
eEZOZFhONVl5QmpaWEowYVdacFkyRjBaVEJjTUEwR0NTcUdTSWIzCkRRRUJBUVVBQTBzQU1F
Z0NRUURHdDNQOFlVZXpid0UzeDFLT2g5dUZTaVRRb0NKekNTbU14eFlSZXBWWkN3VloKTlhu
ZmlzMTcydThIcjN3U0l5V2FuY0IrSzVkTk1nZlQyTTBuVGQrUkFnTUJBQUdqR0RBV01CUUdD
V0NHU0FHRworRUlCQVFFQi93UUVBd0lBRVRBTkJna3Foa2lHOXcwQkFRUUZBQU5CQURkRmkx
TktsdGFYWklvOGI5R2hRZnY3CklxS2ZpRmg1QXUwVDBmT0xhdktDUGtsbmhFaVJrTXpFb3dV
OXJLTDF5S2U2RTYrK3EzL3liM0FsM0JFeTNuVT0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0t
LQo=
--------------B4D4F3A98BE9A5B535835BE6
Content-Type: application/x-unknown-content-type-WinZip; name="RHpk.b64"
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename="RHpk.b64"
X-Sun-Content-Length: 758

LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpQcm9jLVR5cGU6IDQsRU5DUllQVEVE
CkRFSy1JbmZvOiBERVMtRURFMy1DQkMsRkQ2NzBFRDkyRjVBREFBRQoKTHE5UXdWQS9WYW8z
NTJtMEQvTEZnNEJidHZCOEY1SVdMRGRhRHBTa3gzaG1UOEs1U0I5citQVitybHhSazZ3SQpl
VGJQbUgzY0x3RDB6dTRxU015QWRIWkJ0eDVBWDJ3eHhKd2NxcTJuWSswZ3FxeEYxUW1zMFhF
SFJlTlNnTmNWClFLR0NLRis3V05OU1pJdFp6UTVUcEdvUGx0a3poNGZoajZFbkZyeWxZMzNJ
QjREa3FEUFhWd3dMallrSWh6ZTcKQm5xblRYWksxVDhjNFBGOHBnY29TaDNmT0ZpcUV5dE5F
Yy9SN3M1dERLOUp5L3VHREdvcG5FSUI5VHJmMTc5SQpwQzRhRUNia1hxVVRrdnAzRkNvekJi
NXltazVLZ0pqZU0ycXNMaW9CTXE5WlhkL3o4MmVpbVVoZ3c4QURWZ2RRClRxdnd5S1FmY3ha
TXFRT1Q5NnBRWHVxMHd6UHdlWURHcUpNLy91Z1UwcXBRK09SQUJRQUhsMjU3V21OUzIrWUIK
d2wwMkc1VWZ1NEs4eVBGQVJLLzFWUjQvV0xGQi95Ry9USmFmUGd5R0NJcz0KLS0tLS1FTkQg
UlNBIFBSSVZBVEUgS0VZLS0tLS0K
--------------B4D4F3A98BE9A5B535835BE6--

- Next message: Jan Luehe: "Re: Keystore and importing a private key"
- Previous message: Bernard Leach: "DSA and Signature"
- Next in thread: Jan Luehe: "Re: Keystore and importing a private key"