DevelopersVietNam / as3crypto

Automatically exported from code.google.com/p/as3crypto
0 stars 0 forks source link

rsa problem #57

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
hi.
first thing i must to say is: im newbie in as3 and cryptography.
im developing an c++ application and i need to exchange data between c++ app 
and as3 app using rsa.
i have nice c++ code to encrypt/decrypt data using CBigInteger class (i found 
it on internet) and it works. when i crypt something in c++ and decrypt it 
there i have correct result.
also, when i encrypt sth in as3 (using as3crypto) i can decrypt it in my c++ 
app without any error.
problems starts when i try to encrypt in c++ and decrypt it using as3crypto. 
all the time i'm getting error like this:
PKCS#1 unpad: i=0, expected b[i]==2, got b[i]=70
[Fault] exception, information=TypeError: Error #2007: Parametr bytes musi 
mieć wartość inną niż null. (eng: parameter bytes can not be null).

i dont know what to do, it seems that the problem is in BigInteger class.

here is the code i'm using to create rsa key (code from example):

var N:String = 
"C4E3F7212602E1E396C0B6623CF11D26204ACE3E7D26685E037AD2507DCE82FC" + 
                           "28F2D5F8A67FC3AFAB89A6D818D1F4C28CFA548418BD9F8E7426789A67E73E41";
var E:String = "10001";
var D:String = 
"7cd1745aec69096129b1f42da52ac9eae0afebbe0bc2ec89253598dcf454960e" + 
                           "3e5e4ec9f8c87202b986601dd167253ee3fb3fa047e14f1dfd5ccd37e931b29d";
var P:String = 
"f0e4dd1eac5622bd3932860fc749bbc48662edabdf3d2826059acc0251ac0d3b";
var Q:String = 
"d13cb38fbcd06ee9bca330b4000b3dae5dae12b27e5173e4d888c325cda61ab3";
var DMP1:String = 
"b3d5571197fc31b0eb6b4153b425e24c033b054d22b9c8282254fe69d8c8c593";
var DMQ1:String = 
"968ffe89e50d7b72585a79b65cfdb9c1da0963cceb56c3759e57334de5a0ac3f";
var IQMP:String = 
"d9bc4f420e93adad9f007d0e5744c2fe051c9ed9d3c9b65f439a18e13d6e3908";
            // create a key.
var recRSA:RSAKey = RSAKey.parsePrivateKey(N,E,D, P,Q,DMP1,DMQ1,IQMP);

nothing special, just an copy-paste from example file.
same N and E im using in my c++ application to encrypt data.

example from my c++ app:
char input[] = "31323334353637383930"; 
N.__Get(nstr,128,HEX); 
E.__Get(estr,6,HEX); // 6, because i have it like this: char estr[] = "010001";

P.__Get(input,20,HEX);
Q.Mov(P.RsaTrans(E,N)); //encrypt

after that in Q i have 
"6EA16C47A8777245542B4C60FF8B9B6812A543818F5C12622DDC5C15C247AB944C6CEE212EC7DF8
96E7534FE329380EA1DB2A91ED8AB1F27FC1546A849495265"

and when i try to decode it in as3crypto i have an error.

i can decode Q in c++ without any problem. i can decode in c++ any incoming 
data crypted with as3crypto. 
as far as i know im using newest (r28) BigInteger.as 

any idea where im doing sth wrong?

Original issue reported on code.google.com by siara.ka...@gmail.com on 19 Mar 2011 at 10:07