473,382 Members | 1,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

RSA Encryption

Can I encrypt data more than 117 bytes in C# (can use CAPICOM and
Crypto API libraries) using RSA 1024 bit.

Any sample code would be appreciated.

Thanks

Nov 17 '05 #1
13 13526
If you aren’t opposed to using the built in crypto libraries that are part of
..NET, I’d suggest looking at
http://ryanscook.com/adminsBlog/2005...ion-class.html

Brendan
"no game" wrote:
Can I encrypt data more than 117 bytes in C# (can use CAPICOM and
Crypto API libraries) using RSA 1024 bit.

Any sample code would be appreciated.

Thanks

Nov 17 '05 #2
no game <xi********@hotmail.com> wrote:
Can I encrypt data more than 117 bytes in C# (can use CAPICOM and
Crypto API libraries) using RSA 1024 bit.

Any sample code would be appreciated.


I don't see why not - why would more than 117 bytes be a problem?

See RSACryptoServiceProvider for some sample code. (I haven't checked
how good it is.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #3
I think the problem with that solution is that the client and us only
exchange certificate (public key) created by RSA 1024 algorithm, and
the data could be hundreds of bytes. We don't share our algorithm, try
to do everything in standard encryption which the client ask us to do,
we can not tell them there will be a IV and Key to be extracted first
and then do a symmetric decryption.

I know in java, we just need to share our own public key then we can
encrypt and decrypt data.

In C# I have another problem of create a certificate and I can get the
private key into RSAParameter class.

Thanks

Brendan Grant wrote:
If you aren't opposed to using the built in crypto libraries that are part of
.NET, I'd suggest looking at
http://ryanscook.com/adminsBlog/2005...ion-class.html

Brendan
"no game" wrote:
Can I encrypt data more than 117 bytes in C# (can use CAPICOM and
Crypto API libraries) using RSA 1024 bit.

Any sample code would be appreciated.

Thanks


Nov 17 '05 #4
The return byte array of encrypt method is 128 bytes, and there are
also padding, so the longest data is only 117 bytes.

Jon wrote:
no game <xi********@hotmail.com> wrote:
Can I encrypt data more than 117 bytes in C# (can use CAPICOM and
Crypto API libraries) using RSA 1024 bit.

Any sample code would be appreciated.


I don't see why not - why would more than 117 bytes be a problem?

See RSACryptoServiceProvider for some sample code. (I haven't checked
how good it is.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Nov 17 '05 #5
The 117 byte limit is related to the size of the Asymetric key size. You
can only encrypt in block of something < key size depending on what padding
is being used. However, most use a faster symmetric algo like AES
(Rijindael) then encrypt the key and IV with an RSA symmetric key.
--
William Stacey [MVP]

"no game" <xi********@hotmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Can I encrypt data more than 117 bytes in C# (can use CAPICOM and
Crypto API libraries) using RSA 1024 bit.

Any sample code would be appreciated.

Thanks

Nov 17 '05 #6
Before we go any farther here, please outline the steps again. What is the
config. Who is the client, who is the server, or is it peer-to-peer?. Is
A always pulling data from B or both ways? Little more background will
help. Also, as you may know, you don't need certs to use RSA key pairs.

--
William Stacey [MVP]

"no game" <xi********@hotmail.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
I think the problem with that solution is that the client and us only
exchange certificate (public key) created by RSA 1024 algorithm, and
the data could be hundreds of bytes. We don't share our algorithm, try
to do everything in standard encryption which the client ask us to do,
we can not tell them there will be a IV and Key to be extracted first
and then do a symmetric decryption.

I know in java, we just need to share our own public key then we can
encrypt and decrypt data.

In C# I have another problem of create a certificate and I can get the
private key into RSAParameter class.

Thanks

Brendan Grant wrote:
If you aren't opposed to using the built in crypto libraries that are
part of
.NET, I'd suggest looking at
http://ryanscook.com/adminsBlog/2005...ion-class.html

Brendan
"no game" wrote:
> Can I encrypt data more than 117 bytes in C# (can use CAPICOM and
> Crypto API libraries) using RSA 1024 bit.
>
> Any sample code would be appreciated.
>
> Thanks
>
>

Nov 17 '05 #7
The client will send us data encrypted using our public key, which use
RSA 1024bit algorithm, we use our own private key to decrypt the
message, the data send to us will be over 200 bytes, and we also need
to send reply data use their private key too, the data could be 300 or
more bytes. The configuration doesn't include any IV keys and symmetric
algorithm.

Thanks

Nov 17 '05 #8
no game <xi********@hotmail.com> wrote:
The return byte array of encrypt method is 128 bytes, and there are
also padding, so the longest data is only 117 bytes.


Don't use the Encrypt method - use a CryptoStream.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #9
Normally how this works is:
1) Client has your public key only.
2) You have Client's public key only.
3) Client encrypts data with public key and sends (optionally signs hash of
encrypted data using clients private key)
4) You verify signature using clients' public key.
5) You decrypt data using your private key.
6) You encrypt reply using client's public key (optionally sign hash of
encrypted data using your private key)

However asymmetric keys are normally only used to encrypt small amounts of
data like symmetric keys and sign and verify signatures. That is because
asymmetric encryption is many times slower then symmetric encryptions like
AES/Rijndale. So create a new random symmetric key for each request/reply
and encrypt it as above using the RSA keys. Then encrypt the data/payload
with AES and send both the encrypted data and the encrypted key to the other
party. The other party decrypts the symmetric key using its' private RSA
key and decrypts the payload using the session key. The reply can use the
same session key for the encrypted AES reply or start a new.

--
William Stacey [MVP]

"no game" <xi********@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
The client will send us data encrypted using our public key, which use
RSA 1024bit algorithm, we use our own private key to decrypt the
message, the data send to us will be over 200 bytes, and we also need
to send reply data use their private key too, the data could be 300 or
more bytes. The configuration doesn't include any IV keys and symmetric
algorithm.

Thanks

Nov 17 '05 #10
For RSA 1024 bit encryption,

Is it mean the output number of byte is always 128 bytes, and you can
not encrypt more than 128 bytes of data.

Thanks

William Stacey [MVP] wrote:
The 117 byte limit is related to the size of the Asymetric key size. You
can only encrypt in block of something < key size depending on what padding
is being used. However, most use a faster symmetric algo like AES
(Rijindael) then encrypt the key and IV with an RSA symmetric key.
--
William Stacey [MVP]

"no game" <xi********@hotmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Can I encrypt data more than 117 bytes in C# (can use CAPICOM and
Crypto API libraries) using RSA 1024 bit.

Any sample code would be appreciated.

Thanks


Nov 17 '05 #11
That is what I was saying. You can't actually encrypt 128 because of the
padding. Maybe you can if no padding is used, but not sure. It is key size
related, so a larger key can encrypt more bytes. But normally you will want
a symmetric encryption for large amounts of data.

--
William Stacey [MVP]

"no game" <xi********@hotmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
For RSA 1024 bit encryption,

Is it mean the output number of byte is always 128 bytes, and you can
not encrypt more than 128 bytes of data.

Thanks

William Stacey [MVP] wrote:
The 117 byte limit is related to the size of the Asymetric key size. You
can only encrypt in block of something < key size depending on what
padding
is being used. However, most use a faster symmetric algo like AES
(Rijindael) then encrypt the key and IV with an RSA symmetric key.
--
William Stacey [MVP]

"no game" <xi********@hotmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
> Can I encrypt data more than 117 bytes in C# (can use CAPICOM and
> Crypto API libraries) using RSA 1024 bit.
>
> Any sample code would be appreciated.
>
> Thanks
>

Nov 17 '05 #12
Just to confirm, this 128 byte limit is not the limit of C# or .net,
this is a limit set by the RSA 1024 bit algorithm. Am I making the
right statement here?
Thanks

William Stacey [MVP] wrote:
That is what I was saying. You can't actually encrypt 128 because of the
padding. Maybe you can if no padding is used, but not sure. It is key size
related, so a larger key can encrypt more bytes. But normally you will want
a symmetric encryption for large amounts of data.

--
William Stacey [MVP]

"no game" <xi********@hotmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
For RSA 1024 bit encryption,

Is it mean the output number of byte is always 128 bytes, and you can
not encrypt more than 128 bytes of data.

Thanks

William Stacey [MVP] wrote:
The 117 byte limit is related to the size of the Asymetric key size. You
can only encrypt in block of something < key size depending on what
padding
is being used. However, most use a faster symmetric algo like AES
(Rijindael) then encrypt the key and IV with an RSA symmetric key.
--
William Stacey [MVP]

"no game" <xi********@hotmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
> Can I encrypt data more than 117 bytes in C# (can use CAPICOM and
> Crypto API libraries) using RSA 1024 bit.
>
> Any sample code would be appreciated.
>
> Thanks
>


Nov 17 '05 #13
Do you know is there any official document out there that talking about
RSA 1024 means output data is 128 bytes, and RSA 2048 means output data
is 256 bytes etc.

Thanks

Nov 17 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Cliff | last post by:
We are trying to connect to 3 different Oracle databases using MS Access as the front-end and ODBC as the connection. The problem that we are having is that 1 of the databases requires a...
113
by: Bonj | last post by:
I was in need of an encryption algorithm to the following requirements: 1) Must be capable of encrypting strings to a byte array, and decyrpting back again to the same string 2) Must have the same...
7
by: Alan Silver | last post by:
Hello, I am writing a page where sensitive data is collected (over SSL) and stored in a database. I have been looking at the .NET encryption classes, but am a bit confused as to which is best...
2
by: Sumit Gupta | last post by:
Can anyone please tell me how to encrpt string or any kind of Data. Also the Algorithm of Compression. Any Link tutorial etc. Like : Zip or RAR Formats etc.
9
by: sweety | last post by:
Dear All, How to encrypt a C data file and make binary file and then have to read a bin file at run time and decrypt the file and have to read the data. Any help to achive this pls. Would be...
4
by: pintu | last post by:
Hello everybody.. I hav some confusion regarding asymmetric encryption.As asymmetric encryption it there is one private key and one public key.So any data is encrypted using private key and the...
1
by: =?Utf-8?B?bWljcm9ob2Y=?= | last post by:
Short version: Is there a way to configure (preferably programmatically) the max encryption strength that will be used by the framework when connecting to a particular SSL-protected web service? ...
11
by: John Williams | last post by:
I've written a simple program to do XOR encryption as my first foray into understanding how encryption works. The code compiles fine, however it segmentation faults on every run. using gdb to...
22
by: j1mb0jay | last post by:
I have had to create a simple string encryption program for coursework, I have completed the task and now have to do a write up on how it could be improved at a later date. If you could look...
19
by: klenwell | last post by:
Another request for comments here. I'd like to accomplish something like the scheme outlined at this page here: http://tinyurl.com/3dtcdr In a nutshell, the form uses javascript to hash...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.