[prev in list] [next in list] [prev in thread] [next in thread] 

List:       bouncycastle-crypto-dev
Subject:    [dev-crypto] PROBLEM WITH LOADING PRODUCT
From:       "Far" <farhad.kia () gmail ! com>
Date:       2007-05-26 11:41:50
Message-ID: 6EAF465083B144D38201D0F88195AA38 () ExpertPC
[Download RAW message or body]

----- Original Message ----- 
From: Far 
To: dev-crypto@bouncycastle.org 
Sent: Saturday, May 26, 2007 1:38 PM
Subject: PROBLEM WITH Convert public and private key to string and reverse


 --------------------------------------------------------------
       From: Peter Rabbit <farhad.kia@gmail.com>
         To: dev-crypto@bouncycastle.org
    Subject: PROBLEM WITH Convert public and private key to string and reverse

    
i used this code :
convert key to string:
         byte[] pbspecenc=reqpair.getPublic().getEncoded();
        String d=new String(Base64.encode(pbspecenc.toString().getBytes("UTF-8")),"UTF-8");



          byte[] pvspecenc=reqpair.getPrivate().getEncoded();
          String v=new String(Base64.encode(pvspecenc.toString().getBytes("UTF-8")),"UTF-8");


convert string to key :

       EncodedKeySpec newkspec = new X509EncodedKeySpec(Base64.decode(d.getBytes("UTF-8")));
        KeyFactory kf = KeyFactory.getInstance("RSA");
        PublicKey pubf = kf.generatePublic(newkspec); 


        EncodedKeySpec newkspec = new PKCS8EncodedKeySpec(Base64.decode(v.getBytes("UTF-8")));
        KeyFactory kf = KeyFactory.getInstance("RSA");
        PrivateKey pubf = kf.generatePrivate(newkspec); 



ERROR: 

java.security.InvalidKeyException: IOException: null 

when i change  
KeyFactory kf = KeyFactory.getInstance("RSA");
to 
 KeyFactory kf = KeyFactory.getInstance("RSA","BC");


ERROR:
java.io.EOFException: EOF encountered in middle of object 



 --------------------------------------------------------------

[Attachment #3 (text/html)]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6000.16448" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV style="FONT: 10pt arial">----- Original Message ----- 
<DIV style="BACKGROUND: #e4e4e4; font-color: black"><B>From:</B> <A 
title=farhad.kia@gmail.com href="mailto:farhad.kia@gmail.com">Far</A> </DIV>
<DIV><B>To:</B> <A title=dev-crypto@bouncycastle.org 
href="mailto:dev-crypto@bouncycastle.org">dev-crypto@bouncycastle.org</A> </DIV>
<DIV><B>Sent:</B> Saturday, May 26, 2007 1:38 PM</DIV>
<DIV><B>Subject:</B> PROBLEM WITH Convert public and private key to string and 
reverse</DIV></DIV>
<DIV><BR></DIV>
<DIV><FONT face=Arial size=2><FONT face="Times New Roman" 
size=3>&nbsp;--------------------------------------------------------------<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
                
From: Peter Rabbit &lt;</FONT><A href="mailto:farhad.kia@gmail.com"><FONT 
face="Times New Roman" size=3>farhad.kia@gmail.com</FONT></A><FONT 
face="Times New Roman" 
size=3>&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; To: </FONT><A 
href="mailto:dev-crypto@bouncycastle.org"><FONT face="Times New Roman" 
size=3>dev-crypto@bouncycastle.org</FONT></A><BR><FONT face="Times New Roman" 
size=3>&nbsp;&nbsp;&nbsp; Subject: PROBLEM WITH <FONT size=3>Convert public and 
private key to string and reverse</FONT><BR><BR>&nbsp;&nbsp;&nbsp; 
<DIV><FONT face=Arial size=2>i used this code :</FONT></DIV>
<DIV><FONT face=Arial size=2>convert key to string:</FONT></DIV>
<DIV><FONT face=Arial 
size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;byte[] 
pbspecenc=reqpair.getPublic().getEncoded();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
 String d=new 
String(Base64.encode(pbspecenc.toString().getBytes("UTF-8")),"UTF-8");</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial 
size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; byte[] 
pvspecenc=reqpair.getPrivate().getEncoded();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
 String v=new 
String(Base64.encode(pvspecenc.toString().getBytes("UTF-8")),"UTF-8");</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>convert string to key :</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EncodedKeySpec 
newkspec = new 
X509EncodedKeySpec(Base64.decode(d.getBytes("UTF-8")));</FONT></DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
KeyFactory kf = 
KeyFactory.getInstance("RSA");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
PublicKey pubf = kf.generatePublic(newkspec); </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
EncodedKeySpec newkspec = new 
PKCS8EncodedKeySpec(Base64.decode(v.getBytes("UTF-8")));</FONT></DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
KeyFactory kf = 
KeyFactory.getInstance("RSA");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
PrivateKey pubf = kf.generatePrivate(newkspec); </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>ERROR: </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV>java.security.InvalidKeyException: IOException: null </DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>when i change&nbsp; </FONT></DIV>
<DIV><FONT face=Arial size=2>KeyFactory kf = 
KeyFactory.getInstance("RSA");<BR>to </FONT></DIV>
<DIV><FONT face=Arial size=2>&nbsp;KeyFactory kf = 
KeyFactory.getInstance("RSA","BC");</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>ERROR:</FONT></DIV>
<DIV>java.io.EOFException: EOF encountered in middle of object </DIV>
<DIV>&nbsp;</DIV>
<DIV><BR></DIV>&nbsp;--------------------------------------------------------------</FONT><BR></FONT></DIV></BODY></HTML>




[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic