Jump to content

RSA Encryption?


FaridAgl
 Share

Recommended Posts

I have this private key:

-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEA3XK9BWuIHIS3R6za4WU/mQ0WlsPD/ErtzSTw2ZmbhI0lyKcQ
Ugk0aRIOaq4vTE+EpRtI6hvhH4AIm+15sWPqxpfuNR0Dvigse+BhuypFsqI+AWiL
dj5RrPSzrLcqWgjE5zSjUG4OmxS4NJJRY9UMNaEhtqsrgrFFj4iMX07bz6Joyp85
CHpGJhmFjPwU60OlUkGKwvs6TeQXUZlH9ypzXkNAhF4uDchTgEX7A/8yrqHzPx7/
r2T0Lww7kp106ACdy9wXTpq5v3tmfNZbZ7K0bEB4g8Ez43Hew1P5b/tabUV4pZL0
LkvDCA78ll8FHeuJjZA3+DKlEgyA2EWTs98VTQIDAQABAoIBAC65evCd08ZQqmtR
KY3NUzHz9QQyojOli69xT/BZ3NqG/aXsuiDVGF3jFW+k+Q3c6Vv8+dGLuGBxH1/n
J3oqXuswO26xhIym5Vvt6DEZpkMewH6DlImKdKlNqGuU6ja9Cu7NyHe8ARDvuj49
cTbjSQQ3z2k/jJqy1L6ITTX+6ZpRgZd9m/Ng5O0GBcoSiUjysfLgs5m5lHWCojL+
ppxqhsWXDM2ejIFGncGok798NNps+OkAM9EwEHcEI7qBo/UEsgXwnmlUvsyBvtq3
7NS/znsJlOT/PfbS3i0gIac6AmA0qh86zN+uC5yl44aY+WpwPqBua6eeKkpk3xAo
LrCRxHECgYEA/689gaRf0ihJ5WpD/cq6XLFwxuu4/CmmNjYpTwol2S3lGnq03RLZ
FhklvMKIkhfuaOLyrHgUWaYZVr2KBUU81qwHTVEZeN6rWPeXTsfgBnpShIYYXqBN
ePyqVDuISs44Lsi74fhSNrqai6ow6GQYlZewcdjS2zVc35G1of/cWNMCgYEA3biv
L49okrATQfBbdl5L6hueqNc8pfrv6EKYcw5SE48fFeHCToorKpaf4kf7GemITldD
29FFwukhyt1rJJI9Kvj6jKN49QZr3xS1d8QY0lOHnRRRLIg3x+VaD7RYOWuHbqs1
MKyzgeKkpWq6EkuaW2ZEQwL6cvzqGsbo1CRqBV8CgYBMNqEf1q5VR3sXbkCMEvTQ
EngqYzNFvuhzelt/2ueDQCHtbawhxa993csY4+evnICNNTDe5gAy5MbiyyasAYJr
/uVCT61HESCEKXEpo3yMkcOtCweSlTfim3XuG7y5h5TJpT4T0mA3PhI5FWb0rnmB
hbCrjtTzUIm5foZkno7AzwKBgD2PTXSTCKHRqUchiQNwYvt497BBMmGTLpD6DIHF
dBxiHGti5yQPULTeZT3aZmlnYaT+raSWkhvvxqYgm+Lnh3wq7MWnjanaQpEJmujJ
1WpwLrL6NR98IqCpmTvLAsPOiye6+WWuTZi+aKBU5Zy2yQCfgExqw0ax2f3dRD/C
bH1ZAoGAOJ/pLNpetFyE/aaD0jBfMA6UACdutjWT4vFGmk/GwBh3/sHoMbON2c/P
OeEM/N3/ZODOZHzXB1ALgWIjeoP2TegBfbniHf2d+j1/VRMTiYEMv3ws06YiWMLJ
ioX2ZNntCCPlIti48TeFs0etqcHQgQ5rSLblyde3RIuRcqatQko=
-----END RSA PRIVATE KEY-----

And all I know is that I have to encrypt some buffer with this private key (Yes, private key should be used for decryption, not encryption, I guess, but the protocol I am trying to implement works this way.).

Any help would be really great as I'm stucked on this about 2 days.

Thanks in advance.

Link to comment
Share on other sites

Simple googling for "BEGIN RSA PRIVATE KEY" finds this page (for instance) which should answer your question.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

try google: got one on the first link: link

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Simple googling for "BEGIN RSA PRIVATE KEY" finds this page (for instance) which should answer your question.

Thanks, I tried to understand it a bit, not such help thu.

 

try google: got one on the first link: link

I did it before, couldn't find anything useful.

 

Let me ask another way, this is what I'm trying to do:

 

For the session opening, the client generates a 256-bits AES session key, and a

128-bits AES session IV (Initialisation Vector). 
 
The client sends a GSP SESSION INIT message to the server, encrypted with
the client's RSA private key (that is, encrypted with the *private* key). 
Link to comment
Share on other sites

Weird they would request that, as it's not usually the way it's done. You can't even do this in .NET with standard libraries. PHP has a function to do it, or I found this .NET library someone wrote. You can try to translate it to AutoIt, but I imagine it is quite involved. He had to write his own RSA implementation.

http://www.codeproject.com/Articles/38739/RSA-Private-Key-Encryption

Link to comment
Share on other sites

@wraithdu

Thank you so much for showing me the right direction. I'm not sure if you are interested to help me in further steps, in case you are, here is what I came up with:

<?php
// Same as the private key provided in the first post
$file = fopen('key.private', 'r');
$privateKey = fread($file, 8192);
fclose($file);

// Loading the private key
openssl_get_privatekey($privateKey);


// Generating a 256-bit AES session key
$key = pack('h*', 'bcb04b7e103a0cd8b54763051cef08bc55abe029fdebae5e1d417e2ffb2a00a3');
echo 'key: ' . $key . '<br>';

// Generation a 128-bit AES session IV
$iv = pack('h*', 'e9c79b380e82c862d42bc0aba44216c0');
echo 'iv: ' . $iv . '<br>';


// Forming the message to send
$data = $key . $iv;

// Encrypting the data
openssl_private_encrypt($data, $crypted, $privateKey);


// Printing out the result which will be sent to the server
var_dump(unpack('h*', $crypted));
/*
Result:
06e35b380dc705f9b3133c3533dc41ec003480c5428ec006af51abe72d6eb407bb3d3af2d63e8b08f963a2eddce8e0f958aae58342eb28845498ee8d7b41ffd4e9317cc308df86522558dc26b53a8b0a1456adce928f09489ac9bb594f3d24c69938a2debc175f3a80f80ab86c6d20253fe56e1d068eb84318eefcde54682b94930465b05c4fe092aba97adb7ec1f5a8f5713896e1ebeb2f4fed549550d71d4dcf61212ff3d4abeb7f00717b928e5dc7b00ff05bfb54d29f74a5b189995c2238079828c14bea6f056cd708388ef1bc812cccc3b10b0b1c63d36ba90eb2a494d36b6f4f8c356e5ba1295f83b5b664b25495e10576bd5756d443d7302d59bd5771
*/

The server doesn't response to the request, which means I'm not sending the correct message.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...