Hi,
I am using RSA encryption. 
I am using Crypto5.1 for encryption(c++) and bouncy
castle(java) for decryption.
Key generation is done using java key tool.From keys
generated, i am getting public key exponent and
modulus.

I am creating RSAFunction Using public key exponent
and modulus,  and i am using RSAFunction:ApplyFunction
and  BASE64 encoding techinque to return the
encryptedString.when i give this encrypted string i
get junk decrypted msg. On java side i am using RSA
with no padding.

If i Perform Applyfunction on string containing only
integer values i have this problem.(i.e
pToEncrypt="123").
If applyFunction is applied on string containing alpha
chars, i get length of encyrpted data as 1.
Is is this ApplyFunction only for Integer vaues.


I also tried to use
RSAPublicKeyTemplate<EncryptorTemplate<PKCS_EncryptionPaddingScheme,
RSAFunction>, RSAES_PKCS1v15_Decryptor>. For this we
need to provide random seed. what is this?? i just
provided the value 0.
When i decrypt the encrypted string using java ,i get
input data size is too long exception. 
For RSA decryption in java, i have provided
RSA/ECB/PKCS1Padding i.e PKCS1 V 1.5. Random number is
auto generated here. no need to input the random seed.

Pl. anybody has solution for this.


I have just included my c++ sample for both cases



case 1: using RSAFunction


char* TestEncryption::encryptString(string
pToEncrypt){
 char * inputString;
 int len=pToEncrypt.length();
 inputString=new char[len];
 pToEncrypt.copy(inputString, len);
 Integer *inputVal=new Integer(inputString);
 Integer
encryptIntValue=rsaFunction->ApplyFunction(*inputVal);
 Integer::Signedness mysign;
 mysign=(Integer::Signedness)1;
 unsigned int
outputLen=encryptIntValue.MinEncodedSize(mysign);
 cout<<" \n OUTPUT LEN "<<outputLen;
 byte * output=new byte[outputLen];
 encryptIntValue.Encode (output,outputLen,mysign);
 char *outstr;
 int modulus = outputLen% 3;
 if (modulus == 0){
  len=4 * outputLen/ 3;
 }else{
  len=4* ((outputLen/3)+1);
 }
 outstr=new char[len];
 len=len;
 cout<<" \n LEN OF ENCYPTED DATA "<<len;
 Base64Encoder base64Encoder;
 base64Encoder.Put((byte*)output,outputLen);
 base64Encoder.MessageEnd();
 base64Encoder.Get((byte *)outstr,len);
 cout<<"outstr \n "<<outstr;
return outstr;
}


case 2:
RSAPublicKeyTemplate<EncryptorTemplate<PKCS_EncryptionPaddingScheme,
RSAFunction>, RSAES_PKCS1v15_Decryptor>

char* encryptString(string pToEncrypt){

char * inputString;
int len=pToEncrypt.length();
inputString=new char[len];
pToEncrypt.copy(inputString, len);
cout<<"\n INPUT STRING "<<inputString;
Integer *inputVal=new Integer(inputString);
RSAPublicKeyTemplate<EncryptorTemplate<PKCS_EncryptionPaddingScheme,
RSAFunction>, RSAES_PKCS1v15_Decryptor>
 
pubKey(rsaFunction->GetModulus(),rsaFunction->GetExponent());

char seed[1024];
cout << "\nRandom Seed: ";
ws(cin);
                 
cin.getline(seed, 1024);
RandomPool randPool;
randPool.Put((byte *)seed, strlen(seed));
char *outstr = new char[pubKey.CipherTextLength()];
pubKey.Encrypt(randPool, (byte *)inputString,
strlen(inputString), (byte *)outstr);
int outputLen=pubKey.CipherTextLength();
int modulus = outputLen% 3;
if (modulus == 0){
    len=4 * outputLen/ 3;
}else{
    len=4* ((outputLen/3)+1);
}
char *output=new char[len];
Base64Encoder base64Encoder;
base64Encoder.Put((byte*)outstr,outputLen);
base64Encoder.MessageEnd();
base64Encoder.Get((byte *)output,len);
cout<<"output \n "<<output;

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

Reply via email to