|
security
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
RSA Encrypt/Decrypt ProblemsI am trying to encrypt messages typed in a textbox by encrypting them using RSACryptoServiceProvider. If the text is shorter than about 1/2 a sentence, then it works fine. If it is longer, say: "This is my message. It is not very long, however.", then RSA.Encrypt(MessageBytes, False) fails with "Bad Length". I know that RSA is usually used for encrypting small amounts of data, such as symmetric keys, but all the examples I have seen haven't mention this. Even Microsoft's Training Kit for their Microsoft Certified Professional Exam 70-330 (Implementing Application Security) asks you to build a program that encrypts entire files using RSA. Can anyone provide a definite answer as to whether I can use RSA for what I am doing? Thanks a lot for any response, as I have worked about 10 hours on this! dim message as string = "A longer string than an encryption key.......MessageText" dim unencryptedbytes() as byte = encoding.unicode.getbytes(message) dim RSA as new RSACryptoServiceProvider() RSA.FromXMLString(MyPrivateKey) dim encrypted() as byte = rsa.encrypt(unencryptedbytes, false) 'Errors here Joseph MCAD Hi Joseph MCAD,
the size limit is: 128-11=117 bytes for PKCS#1 v 1.5 padding. output is always 128 byte other details: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityCryptographyRSACryptoServiceProviderClassEncryptTopic.asp HTH Marcello www.cantelmosoftware.com try my Goliath.NET obfuscator (pre-release version) & send me your opinion ;-) http://xoomer.virgilio.it/cantelmosoftware/net/TryMe.zip Show quote "Joseph MCAD" <JosephM***@discussions.microsoft.com> ha scritto nel messaggio news:4CD6D9DF-D97A-444C-81D5-7FD2C57FFD21@microsoft.com... > > March 18, 2005 > > I am trying to encrypt messages typed in a textbox by encrypting them > using RSACryptoServiceProvider. If the text is shorter than about 1/2 a > sentence, then it works fine. If it is longer, say: "This is my message. > It > is not very long, however.", then RSA.Encrypt(MessageBytes, False) fails > with > "Bad Length". I know that RSA is usually used for encrypting small amounts > of > data, such as symmetric keys, but all the examples I have seen haven't > mention this. Even Microsoft's Training Kit for their Microsoft Certified > Professional Exam 70-330 (Implementing Application Security) asks you to > build a program that encrypts entire files using RSA. Can anyone provide a > definite answer as to whether I can use RSA for what I am doing? Thanks a > lot > for any response, as I have worked about 10 hours on this! > > dim message as string = "A longer string than an encryption > key.......MessageText" > dim unencryptedbytes() as byte = encoding.unicode.getbytes(message) > dim RSA as new RSACryptoServiceProvider() > RSA.FromXMLString(MyPrivateKey) > dim encrypted() as byte = rsa.encrypt(unencryptedbytes, false) 'Errors > here > > > Joseph MCAD > > oops! :-)
other my modest tips: change "unicode" to "default": dim unencryptedbytes() as byte = encoding.default.getbytes(message) HTH Marcello www.cantelmosoftware.com Show quote "Cantelmo Software" <i***@cantelmosoftware.com> ha scritto nel messaggio news:OzsCYhBLFHA.436@TK2MSFTNGP09.phx.gbl... > Hi Joseph MCAD, > the size limit is: 128-11=117 bytes for PKCS#1 v 1.5 padding. output is > always 128 byte > > other details: > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityCryptographyRSACryptoServiceProviderClassEncryptTopic.asp > > HTH > Marcello > www.cantelmosoftware.com > > try my Goliath.NET obfuscator (pre-release version) & send me your opinion > ;-) > http://xoomer.virgilio.it/cantelmosoftware/net/TryMe.zip > > > "Joseph MCAD" <JosephM***@discussions.microsoft.com> ha scritto nel > messaggio news:4CD6D9DF-D97A-444C-81D5-7FD2C57FFD21@microsoft.com... >> >> March 18, 2005 >> >> I am trying to encrypt messages typed in a textbox by encrypting them >> using RSACryptoServiceProvider. If the text is shorter than about 1/2 a >> sentence, then it works fine. If it is longer, say: "This is my message. >> It >> is not very long, however.", then RSA.Encrypt(MessageBytes, False) fails >> with >> "Bad Length". I know that RSA is usually used for encrypting small >> amounts of >> data, such as symmetric keys, but all the examples I have seen haven't >> mention this. Even Microsoft's Training Kit for their Microsoft Certified >> Professional Exam 70-330 (Implementing Application Security) asks you to >> build a program that encrypts entire files using RSA. Can anyone provide >> a >> definite answer as to whether I can use RSA for what I am doing? Thanks a >> lot >> for any response, as I have worked about 10 hours on this! >> >> dim message as string = "A longer string than an encryption >> key.......MessageText" >> dim unencryptedbytes() as byte = encoding.unicode.getbytes(message) >> dim RSA as new RSACryptoServiceProvider() >> RSA.FromXMLString(MyPrivateKey) >> dim encrypted() as byte = rsa.encrypt(unencryptedbytes, false) 'Errors >> here >> >> >> Joseph MCAD >> >> > > March 18, 2005
Thanks! I have looked for a very long time for those byte length numbers! One problem though. :( If I am right, Encoding.Unicode.Getbytes() converts each character to two bytes. That means that I cannot evenly feed the bytes to RSA without splitting characters. Will this be a problem, and am I right that .GetBytes() converts chars to two bytes? Also do you know of a way to split the UnEncrypted() byte array into blocks of 127? Right now, I have tried to input the message into a stringreader and then read back blocks of 50 chars at a time. I then convert the block of chars to bytes and feed the block of bytes to the encryptor. This works, but I for some reason cannot decrypt it. (I just realized that I encrypted using the private key and then decrypted using the private key. Do I have to create another rsa object with JUST the public key, or can I decrypt using the same RSA since it has both the private and public key?) I guess I am just really confused and I Really Appreciate your help! Joseph MCAD Show quote "Cantelmo Software" wrote: > Hi Joseph MCAD, > the size limit is: 128-11=117 bytes for PKCS#1 v 1.5 padding. output is > always 128 byte > > other details: > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityCryptographyRSACryptoServiceProviderClassEncryptTopic.asp > > HTH > Marcello > www.cantelmosoftware.com > > try my Goliath.NET obfuscator (pre-release version) & send me your opinion > ;-) > http://xoomer.virgilio.it/cantelmosoftware/net/TryMe.zip > > > "Joseph MCAD" <JosephM***@discussions.microsoft.com> ha scritto nel > messaggio news:4CD6D9DF-D97A-444C-81D5-7FD2C57FFD21@microsoft.com... > > > > March 18, 2005 > > > > I am trying to encrypt messages typed in a textbox by encrypting them > > using RSACryptoServiceProvider. If the text is shorter than about 1/2 a > > sentence, then it works fine. If it is longer, say: "This is my message. > > It > > is not very long, however.", then RSA.Encrypt(MessageBytes, False) fails > > with > > "Bad Length". I know that RSA is usually used for encrypting small amounts > > of > > data, such as symmetric keys, but all the examples I have seen haven't > > mention this. Even Microsoft's Training Kit for their Microsoft Certified > > Professional Exam 70-330 (Implementing Application Security) asks you to > > build a program that encrypts entire files using RSA. Can anyone provide a > > definite answer as to whether I can use RSA for what I am doing? Thanks a > > lot > > for any response, as I have worked about 10 hours on this! > > > > dim message as string = "A longer string than an encryption > > key.......MessageText" > > dim unencryptedbytes() as byte = encoding.unicode.getbytes(message) > > dim RSA as new RSACryptoServiceProvider() > > RSA.FromXMLString(MyPrivateKey) > > dim encrypted() as byte = rsa.encrypt(unencryptedbytes, false) 'Errors > > here > > > > > > Joseph MCAD > > > > > > > Hi Joseph,
as I have already suggested (in second message) to you uses "default" instead of "unicode" also in phase of decrypt! attention! since it is possible to gain the public key from that private key, I in my programs encrypt with the private key and decrypt with the public key. :-o in this way even if someone crack my program cannot sign of new the keys...why it does not know that private key! ;-) HTH Marcello www.cantelmosoftware.com p.s.: sorry for my bad english. i'm italian Show quote "Joseph MCAD" <JosephM***@discussions.microsoft.com> ha scritto nel messaggio news:5E4D3B47-B809-43A3-A8AC-D7E461BB5E61@microsoft.com... > > March 18, 2005 > > Thanks! I have looked for a very long time for those byte length > numbers! One problem though. :( If I am right, > Encoding.Unicode.Getbytes() > converts each character to two bytes. That means that I cannot evenly > feed > the bytes to RSA without splitting characters. Will this be a problem, and > am > I right that .GetBytes() converts chars to two bytes? Also do you know of > a > way to split the UnEncrypted() byte array into blocks of 127? Right now, I > have tried to input the message into a stringreader and then read back > blocks > of 50 chars at a time. I then convert the block of chars to bytes and feed > the block of bytes to the encryptor. This works, but I for some reason > cannot > decrypt it. (I just realized that I encrypted using the private key and > then > decrypted using the private key. Do I have to create another rsa object > with > JUST the public key, or can I decrypt using the same RSA since it has both > the private and public key?) I guess I am just really confused and I > Really > Appreciate your help! > > > Joseph MCAD > > > > "Cantelmo Software" wrote: > >> Hi Joseph MCAD, >> the size limit is: 128-11=117 bytes for PKCS#1 v 1.5 padding. output is >> always 128 byte >> >> other details: >> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityCryptographyRSACryptoServiceProviderClassEncryptTopic.asp >> >> HTH >> Marcello >> www.cantelmosoftware.com >> >> try my Goliath.NET obfuscator (pre-release version) & send me your >> opinion >> ;-) >> http://xoomer.virgilio.it/cantelmosoftware/net/TryMe.zip >> >> >> "Joseph MCAD" <JosephM***@discussions.microsoft.com> ha scritto nel >> messaggio news:4CD6D9DF-D97A-444C-81D5-7FD2C57FFD21@microsoft.com... >> > >> > March 18, 2005 >> > >> > I am trying to encrypt messages typed in a textbox by encrypting >> > them >> > using RSACryptoServiceProvider. If the text is shorter than about 1/2 a >> > sentence, then it works fine. If it is longer, say: "This is my >> > message. >> > It >> > is not very long, however.", then RSA.Encrypt(MessageBytes, False) >> > fails >> > with >> > "Bad Length". I know that RSA is usually used for encrypting small >> > amounts >> > of >> > data, such as symmetric keys, but all the examples I have seen haven't >> > mention this. Even Microsoft's Training Kit for their Microsoft >> > Certified >> > Professional Exam 70-330 (Implementing Application Security) asks you >> > to >> > build a program that encrypts entire files using RSA. Can anyone >> > provide a >> > definite answer as to whether I can use RSA for what I am doing? Thanks >> > a >> > lot >> > for any response, as I have worked about 10 hours on this! >> > >> > dim message as string = "A longer string than an encryption >> > key.......MessageText" >> > dim unencryptedbytes() as byte = encoding.unicode.getbytes(message) >> > dim RSA as new RSACryptoServiceProvider() >> > RSA.FromXMLString(MyPrivateKey) >> > dim encrypted() as byte = rsa.encrypt(unencryptedbytes, false) 'Errors >> > here >> > >> > >> > Joseph MCAD >> > >> > >> >> >> in kind, for who it does not have much practical one of encryption, it can
use RSA in order to crypt KEY and IV of an algorithm to symmetrical key DES, 3DES, etc. in this way you resolve the problems of 127 the greater blocks of byte good job, Marcello Show quote "Cantelmo Software" <i***@cantelmosoftware.com> ha scritto nel messaggio news:OSrikyBLFHA.3928@TK2MSFTNGP09.phx.gbl... > Hi Joseph, > as I have already suggested (in second message) to you uses "default" > instead of "unicode" also in phase of decrypt! > > attention! since it is possible to gain the public key from that private > key, I in my programs encrypt with the private key and decrypt with the > public key. :-o > > in this way even if someone crack my program cannot sign of new the > keys...why it does not know that private key! ;-) > > HTH > Marcello > www.cantelmosoftware.com > > p.s.: sorry for my bad english. i'm italian > > "Joseph MCAD" <JosephM***@discussions.microsoft.com> ha scritto nel > messaggio news:5E4D3B47-B809-43A3-A8AC-D7E461BB5E61@microsoft.com... >> >> March 18, 2005 >> >> Thanks! I have looked for a very long time for those byte length >> numbers! One problem though. :( If I am right, >> Encoding.Unicode.Getbytes() >> converts each character to two bytes. That means that I cannot evenly >> feed >> the bytes to RSA without splitting characters. Will this be a problem, >> and am >> I right that .GetBytes() converts chars to two bytes? Also do you know of >> a >> way to split the UnEncrypted() byte array into blocks of 127? Right now, >> I >> have tried to input the message into a stringreader and then read back >> blocks >> of 50 chars at a time. I then convert the block of chars to bytes and >> feed >> the block of bytes to the encryptor. This works, but I for some reason >> cannot >> decrypt it. (I just realized that I encrypted using the private key and >> then >> decrypted using the private key. Do I have to create another rsa object >> with >> JUST the public key, or can I decrypt using the same RSA since it has >> both >> the private and public key?) I guess I am just really confused and I >> Really >> Appreciate your help! >> >> >> Joseph MCAD >> >> >> >> "Cantelmo Software" wrote: >> >>> Hi Joseph MCAD, >>> the size limit is: 128-11=117 bytes for PKCS#1 v 1.5 padding. output is >>> always 128 byte >>> >>> other details: >>> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityCryptographyRSACryptoServiceProviderClassEncryptTopic.asp >>> >>> HTH >>> Marcello >>> www.cantelmosoftware.com >>> >>> try my Goliath.NET obfuscator (pre-release version) & send me your >>> opinion >>> ;-) >>> http://xoomer.virgilio.it/cantelmosoftware/net/TryMe.zip >>> >>> >>> "Joseph MCAD" <JosephM***@discussions.microsoft.com> ha scritto nel >>> messaggio news:4CD6D9DF-D97A-444C-81D5-7FD2C57FFD21@microsoft.com... >>> > >>> > March 18, 2005 >>> > >>> > I am trying to encrypt messages typed in a textbox by encrypting >>> > them >>> > using RSACryptoServiceProvider. If the text is shorter than about 1/2 >>> > a >>> > sentence, then it works fine. If it is longer, say: "This is my >>> > message. >>> > It >>> > is not very long, however.", then RSA.Encrypt(MessageBytes, False) >>> > fails >>> > with >>> > "Bad Length". I know that RSA is usually used for encrypting small >>> > amounts >>> > of >>> > data, such as symmetric keys, but all the examples I have seen haven't >>> > mention this. Even Microsoft's Training Kit for their Microsoft >>> > Certified >>> > Professional Exam 70-330 (Implementing Application Security) asks you >>> > to >>> > build a program that encrypts entire files using RSA. Can anyone >>> > provide a >>> > definite answer as to whether I can use RSA for what I am doing? >>> > Thanks a >>> > lot >>> > for any response, as I have worked about 10 hours on this! >>> > >>> > dim message as string = "A longer string than an encryption >>> > key.......MessageText" >>> > dim unencryptedbytes() as byte = encoding.unicode.getbytes(message) >>> > dim RSA as new RSACryptoServiceProvider() >>> > RSA.FromXMLString(MyPrivateKey) >>> > dim encrypted() as byte = rsa.encrypt(unencryptedbytes, false) 'Errors >>> > here >>> > >>> > >>> > Joseph MCAD >>> > >>> > >>> >>> >>> > > March 18, 2005
If I understand your post right, you are saying that a practical use of RSA is to encypt the IV or the Key of a symmectrical algorithm. If that is the case, then is it very unrealistic in a job to try to encrypt whole files with RSA such as in the training kit book? I am confused, because RSA is supposed to be able to have a 2048 byte key and I would think that it could handle a large size. Thanks for all help! Joseph MCAD Show quote "Cantelmo Software" wrote: > in kind, for who it does not have much practical one of encryption, it can > use RSA in order to crypt KEY and IV of an algorithm to symmetrical key DES, > 3DES, etc. in this way you resolve the problems of 127 the greater blocks of > byte > > good job, > Marcello > > "Cantelmo Software" <i***@cantelmosoftware.com> ha scritto nel messaggio > news:OSrikyBLFHA.3928@TK2MSFTNGP09.phx.gbl... > > Hi Joseph, > > as I have already suggested (in second message) to you uses "default" > > instead of "unicode" also in phase of decrypt! > > > > attention! since it is possible to gain the public key from that private > > key, I in my programs encrypt with the private key and decrypt with the > > public key. :-o > > > > in this way even if someone crack my program cannot sign of new the > > keys...why it does not know that private key! ;-) > > > > HTH > > Marcello > > www.cantelmosoftware.com > > > > p.s.: sorry for my bad english. i'm italian > > > > "Joseph MCAD" <JosephM***@discussions.microsoft.com> ha scritto nel > > messaggio news:5E4D3B47-B809-43A3-A8AC-D7E461BB5E61@microsoft.com... > >> > >> March 18, 2005 > >> > >> Thanks! I have looked for a very long time for those byte length > >> numbers! One problem though. :( If I am right, > >> Encoding.Unicode.Getbytes() > >> converts each character to two bytes. That means that I cannot evenly > >> feed > >> the bytes to RSA without splitting characters. Will this be a problem, > >> and am > >> I right that .GetBytes() converts chars to two bytes? Also do you know of > >> a > >> way to split the UnEncrypted() byte array into blocks of 127? Right now, > >> I > >> have tried to input the message into a stringreader and then read back > >> blocks > >> of 50 chars at a time. I then convert the block of chars to bytes and > >> feed > >> the block of bytes to the encryptor. This works, but I for some reason > >> cannot > >> decrypt it. (I just realized that I encrypted using the private key and > >> then > >> decrypted using the private key. Do I have to create another rsa object > >> with > >> JUST the public key, or can I decrypt using the same RSA since it has > >> both > >> the private and public key?) I guess I am just really confused and I > >> Really > >> Appreciate your help! > >> > >> > >> Joseph MCAD > >> > >> > >> > >> "Cantelmo Software" wrote: > >> > >>> Hi Joseph MCAD, > >>> the size limit is: 128-11=117 bytes for PKCS#1 v 1.5 padding. output is > >>> always 128 byte > >>> > >>> other details: > >>> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityCryptographyRSACryptoServiceProviderClassEncryptTopic.asp > >>> > >>> HTH > >>> Marcello > >>> www.cantelmosoftware.com > >>> > >>> try my Goliath.NET obfuscator (pre-release version) & send me your > >>> opinion > >>> ;-) > >>> http://xoomer.virgilio.it/cantelmosoftware/net/TryMe.zip > >>> > >>> > >>> "Joseph MCAD" <JosephM***@discussions.microsoft.com> ha scritto nel > >>> messaggio news:4CD6D9DF-D97A-444C-81D5-7FD2C57FFD21@microsoft.com... > >>> > > >>> > March 18, 2005 > >>> > > >>> > I am trying to encrypt messages typed in a textbox by encrypting > >>> > them > >>> > using RSACryptoServiceProvider. If the text is shorter than about 1/2 > >>> > a > >>> > sentence, then it works fine. If it is longer, say: "This is my > >>> > message. > >>> > It > >>> > is not very long, however.", then RSA.Encrypt(MessageBytes, False) > >>> > fails > >>> > with > >>> > "Bad Length". I know that RSA is usually used for encrypting small > >>> > amounts > >>> > of > >>> > data, such as symmetric keys, but all the examples I have seen haven't > >>> > mention this. Even Microsoft's Training Kit for their Microsoft > >>> > Certified > >>> > Professional Exam 70-330 (Implementing Application Security) asks you > >>> > to > >>> > build a program that encrypts entire files using RSA. Can anyone > >>> > provide a > >>> > definite answer as to whether I can use RSA for what I am doing? > >>> > Thanks a > >>> > lot > >>> > for any response, as I have worked about 10 hours on this! > >>> > > >>> > dim message as string = "A longer string than an encryption > >>> > key.......MessageText" > >>> > dim unencryptedbytes() as byte = encoding.unicode.getbytes(message) > >>> > dim RSA as new RSACryptoServiceProvider() > >>> > RSA.FromXMLString(MyPrivateKey) > >>> > dim encrypted() as byte = rsa.encrypt(unencryptedbytes, false) 'Errors > >>> > here > >>> > > >>> > > >>> > Joseph MCAD > >>> > > >>> > > >>> > >>> > >>> > > > > > > > Hi Joseph,
if you have understood well you must support a examination microsoft! beyond to the code you have need sure to understand as RSA works. it remembers that the hardness of the algo satisfied with the slowness ! RSA it is *not impossible* to cracked ! it has not been found no mathematical way for factoring great entire numbers. an attack can be only used brute force attack. it is alone, a time issue !!! 640, 1024 or 2048 military key :-ooo ...modification only the byte in output (for hard-strong factoring). what depends must protect. for your data ok! but a application can however be cracked ! (...by stepping into your code...and read your keys!). http://www.rsasecurity.com/rsalabs/node.asp?id=2093 challange for RSA cracked key! start from: http://www.rsasecurity.com/rsalabs/ http://www.rsasecurity.com/rsalabs/node.asp?id=2214 http://www.di-mgt.com.au/rsa_alg.html http://mathworld.wolfram.com/RSAEncryption.html and, above all: MSDN is your friend! if you cannot yourself be allowed to acquire MSDN library you can read all online ;-) in order to study as microsoft same it has implemented this strong algorithm in the .net framework Marcello www.cantelmosoftware.com Show quote "Joseph MCAD" <JosephM***@discussions.microsoft.com> ha scritto nel messaggio news:3238F669-BAA5-48A9-B9F2-27C3966F9F9D@microsoft.com... > > March 18, 2005 > > If I understand your post right, you are saying that a practical use > of > RSA is to encypt the IV or the Key of a symmectrical algorithm. If that is > the case, then is it very unrealistic in a job to try to encrypt whole > files > with RSA such as in the training kit book? I am confused, because RSA is > supposed to be able to have a 2048 byte key and I would think that it > could > handle a large size. Thanks for all help! > > > Joseph MCAD > > > > "Cantelmo Software" wrote: > >> in kind, for who it does not have much practical one of encryption, it >> can >> use RSA in order to crypt KEY and IV of an algorithm to symmetrical key >> DES, >> 3DES, etc. in this way you resolve the problems of 127 the greater blocks >> of >> byte >> >> good job, >> Marcello >> >> "Cantelmo Software" <i***@cantelmosoftware.com> ha scritto nel messaggio >> news:OSrikyBLFHA.3928@TK2MSFTNGP09.phx.gbl... >> > Hi Joseph, >> > as I have already suggested (in second message) to you uses "default" >> > instead of "unicode" also in phase of decrypt! >> > >> > attention! since it is possible to gain the public key from that >> > private >> > key, I in my programs encrypt with the private key and decrypt with the >> > public key. :-o >> > >> > in this way even if someone crack my program cannot sign of new the >> > keys...why it does not know that private key! ;-) >> > >> > HTH >> > Marcello >> > www.cantelmosoftware.com >> > >> > p.s.: sorry for my bad english. i'm italian >> > >> > "Joseph MCAD" <JosephM***@discussions.microsoft.com> ha scritto nel >> > messaggio news:5E4D3B47-B809-43A3-A8AC-D7E461BB5E61@microsoft.com... >> >> >> >> March 18, 2005 >> >> >> >> Thanks! I have looked for a very long time for those byte length >> >> numbers! One problem though. :( If I am right, >> >> Encoding.Unicode.Getbytes() >> >> converts each character to two bytes. That means that I cannot evenly >> >> feed >> >> the bytes to RSA without splitting characters. Will this be a problem, >> >> and am >> >> I right that .GetBytes() converts chars to two bytes? Also do you know >> >> of >> >> a >> >> way to split the UnEncrypted() byte array into blocks of 127? Right >> >> now, >> >> I >> >> have tried to input the message into a stringreader and then read back >> >> blocks >> >> of 50 chars at a time. I then convert the block of chars to bytes and >> >> feed >> >> the block of bytes to the encryptor. This works, but I for some reason >> >> cannot >> >> decrypt it. (I just realized that I encrypted using the private key >> >> and >> >> then >> >> decrypted using the private key. Do I have to create another rsa >> >> object >> >> with >> >> JUST the public key, or can I decrypt using the same RSA since it has >> >> both >> >> the private and public key?) I guess I am just really confused and I >> >> Really >> >> Appreciate your help! >> >> >> >> >> >> Joseph MCAD >> >> >> >> >> >> >> >> "Cantelmo Software" wrote: >> >> >> >>> Hi Joseph MCAD, >> >>> the size limit is: 128-11=117 bytes for PKCS#1 v 1.5 padding. output >> >>> is >> >>> always 128 byte >> >>> >> >>> other details: >> >>> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityCryptographyRSACryptoServiceProviderClassEncryptTopic.asp >> >>> >> >>> HTH >> >>> Marcello >> >>> www.cantelmosoftware.com >> >>> >> >>> try my Goliath.NET obfuscator (pre-release version) & send me your >> >>> opinion >> >>> ;-) >> >>> http://xoomer.virgilio.it/cantelmosoftware/net/TryMe.zip >> >>> >> >>> >> >>> "Joseph MCAD" <JosephM***@discussions.microsoft.com> ha scritto nel >> >>> messaggio news:4CD6D9DF-D97A-444C-81D5-7FD2C57FFD21@microsoft.com... >> >>> > >> >>> > March 18, 2005 >> >>> > >> >>> > I am trying to encrypt messages typed in a textbox by >> >>> > encrypting >> >>> > them >> >>> > using RSACryptoServiceProvider. If the text is shorter than about >> >>> > 1/2 >> >>> > a >> >>> > sentence, then it works fine. If it is longer, say: "This is my >> >>> > message. >> >>> > It >> >>> > is not very long, however.", then RSA.Encrypt(MessageBytes, False) >> >>> > fails >> >>> > with >> >>> > "Bad Length". I know that RSA is usually used for encrypting small >> >>> > amounts >> >>> > of >> >>> > data, such as symmetric keys, but all the examples I have seen >> >>> > haven't >> >>> > mention this. Even Microsoft's Training Kit for their Microsoft >> >>> > Certified >> >>> > Professional Exam 70-330 (Implementing Application Security) asks >> >>> > you >> >>> > to >> >>> > build a program that encrypts entire files using RSA. Can anyone >> >>> > provide a >> >>> > definite answer as to whether I can use RSA for what I am doing? >> >>> > Thanks a >> >>> > lot >> >>> > for any response, as I have worked about 10 hours on this! >> >>> > >> >>> > dim message as string = "A longer string than an encryption >> >>> > key.......MessageText" >> >>> > dim unencryptedbytes() as byte = encoding.unicode.getbytes(message) >> >>> > dim RSA as new RSACryptoServiceProvider() >> >>> > RSA.FromXMLString(MyPrivateKey) >> >>> > dim encrypted() as byte = rsa.encrypt(unencryptedbytes, false) >> >>> > 'Errors >> >>> > here >> >>> > >> >>> > >> >>> > Joseph MCAD >> >>> > >> >>> > >> >>> >> >>> >> >>> >> > >> > >> >> >> I would not break into pieces to do rsa encryption. Just use Rijndael
encryption. Use something like so: public class Doc { public byte[] Key; public byte[] IV; public byte[] Data } Then just create a Rijndael object that will have a new random key and iv. Encrypt your all your data using rij (say maybe an xml doc with all your textbox fields as elements) and store in Data. Then encrypt your key and iv using the public RSA key. Then just serialize the Doc class above using XmlSerializer into an Xml string and send to the receiver. Receiver does the reverse to get the data. No clear encryption key stored anywhere and each new run will have different key and iv. hth. "Joseph MCAD" <JosephM***@discussions.microsoft.com> wrote in message Encoding.Unicode.Getbytes()news:5E4D3B47-B809-43A3-A8AC-D7E461BB5E61@microsoft.com... > > March 18, 2005 > > Thanks! I have looked for a very long time for those byte length > numbers! One problem though. :( If I am right, Show quote > converts each character to two bytes. That means that I cannot evenly http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityCryptographyRSACryptoServiceProviderClassEncryptTopic.aspfeed > the bytes to RSA without splitting characters. Will this be a problem, and am > I right that .GetBytes() converts chars to two bytes? Also do you know of a > way to split the UnEncrypted() byte array into blocks of 127? Right now, I > have tried to input the message into a stringreader and then read back blocks > of 50 chars at a time. I then convert the block of chars to bytes and feed > the block of bytes to the encryptor. This works, but I for some reason cannot > decrypt it. (I just realized that I encrypted using the private key and then > decrypted using the private key. Do I have to create another rsa object with > JUST the public key, or can I decrypt using the same RSA since it has both > the private and public key?) I guess I am just really confused and I Really > Appreciate your help! > > > Joseph MCAD > > > > "Cantelmo Software" wrote: > > > Hi Joseph MCAD, > > the size limit is: 128-11=117 bytes for PKCS#1 v 1.5 padding. output is > > always 128 byte > > > > other details: > > Show quote > > > > HTH > > Marcello > > www.cantelmosoftware.com > > > > try my Goliath.NET obfuscator (pre-release version) & send me your opinion > > ;-) > > http://xoomer.virgilio.it/cantelmosoftware/net/TryMe.zip > > > > > > "Joseph MCAD" <JosephM***@discussions.microsoft.com> ha scritto nel > > messaggio news:4CD6D9DF-D97A-444C-81D5-7FD2C57FFD21@microsoft.com... > > > > > > March 18, 2005 > > > > > > I am trying to encrypt messages typed in a textbox by encrypting them > > > using RSACryptoServiceProvider. If the text is shorter than about 1/2 a > > > sentence, then it works fine. If it is longer, say: "This is my message. > > > It > > > is not very long, however.", then RSA.Encrypt(MessageBytes, False) fails > > > with > > > "Bad Length". I know that RSA is usually used for encrypting small amounts > > > of > > > data, such as symmetric keys, but all the examples I have seen haven't > > > mention this. Even Microsoft's Training Kit for their Microsoft Certified > > > Professional Exam 70-330 (Implementing Application Security) asks you to > > > build a program that encrypts entire files using RSA. Can anyone provide a > > > definite answer as to whether I can use RSA for what I am doing? Thanks a > > > lot > > > for any response, as I have worked about 10 hours on this! > > > > > > dim message as string = "A longer string than an encryption > > > key.......MessageText" > > > dim unencryptedbytes() as byte = encoding.unicode.getbytes(message) > > > dim RSA as new RSACryptoServiceProvider() > > > RSA.FromXMLString(MyPrivateKey) > > > dim encrypted() as byte = rsa.encrypt(unencryptedbytes, false) 'Errors > > > here > > > > > > > > > Joseph MCAD > > > > > > > > > > > > Hi William,
if encrypt the simmetric-key with rsa public-key means that the customer must have the private-key for the decrypt! this goes well in the normal documents (generic data) but *not* for the applications (absolutely no!) why is possible to gain the public-key from that private-key! in the software applications (as an example in the generation of a serial number) it must be used rsa to the contrary. encrypt with the private key and decrypt with that public-key. in this way I have only the certainty that is *not possible* to make a keygen why the private-key lacks! best regards, Marcello www.cantelmosoftware.com Show quote "William Stacey [MVP]" <staceywREM***@mvps.org> ha scritto nel messaggio news:uE7xfNCLFHA.2604@TK2MSFTNGP10.phx.gbl... >I would not break into pieces to do rsa encryption. Just use Rijndael > encryption. Use something like so: > > public class Doc > { > public byte[] Key; > public byte[] IV; > public byte[] Data > } > > Then just create a Rijndael object that will have a new random key and iv. > Encrypt your all your data using rij (say maybe an xml doc with all your > textbox fields as elements) and store in Data. Then encrypt your key and > iv > using the public RSA key. Then just serialize the Doc class above using > XmlSerializer into an Xml string and send to the receiver. Receiver does > the reverse to get the data. No clear encryption key stored anywhere and > each new run will have different key and iv. hth. > > -- > William Stacey, MVP > http://mvp.support.microsoft.com > > "Joseph MCAD" <JosephM***@discussions.microsoft.com> wrote in message > news:5E4D3B47-B809-43A3-A8AC-D7E461BB5E61@microsoft.com... >> >> March 18, 2005 >> >> Thanks! I have looked for a very long time for those byte length >> numbers! One problem though. :( If I am right, > Encoding.Unicode.Getbytes() >> converts each character to two bytes. That means that I cannot evenly > feed >> the bytes to RSA without splitting characters. Will this be a problem, >> and > am >> I right that .GetBytes() converts chars to two bytes? Also do you know of > a >> way to split the UnEncrypted() byte array into blocks of 127? Right now, >> I >> have tried to input the message into a stringreader and then read back > blocks >> of 50 chars at a time. I then convert the block of chars to bytes and >> feed >> the block of bytes to the encryptor. This works, but I for some reason > cannot >> decrypt it. (I just realized that I encrypted using the private key and > then >> decrypted using the private key. Do I have to create another rsa object > with >> JUST the public key, or can I decrypt using the same RSA since it has >> both >> the private and public key?) I guess I am just really confused and I > Really >> Appreciate your help! >> >> >> Joseph MCAD >> >> >> >> "Cantelmo Software" wrote: >> >> > Hi Joseph MCAD, >> > the size limit is: 128-11=117 bytes for PKCS#1 v 1.5 padding. output is >> > always 128 byte >> > >> > other details: >> > > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityCryptographyRSACryptoServiceProviderClassEncryptTopic.asp >> > >> > HTH >> > Marcello >> > www.cantelmosoftware.com >> > >> > try my Goliath.NET obfuscator (pre-release version) & send me your > opinion >> > ;-) >> > http://xoomer.virgilio.it/cantelmosoftware/net/TryMe.zip >> > >> > >> > "Joseph MCAD" <JosephM***@discussions.microsoft.com> ha scritto nel >> > messaggio news:4CD6D9DF-D97A-444C-81D5-7FD2C57FFD21@microsoft.com... >> > > >> > > March 18, 2005 >> > > >> > > I am trying to encrypt messages typed in a textbox by encrypting > them >> > > using RSACryptoServiceProvider. If the text is shorter than about 1/2 > a >> > > sentence, then it works fine. If it is longer, say: "This is my > message. >> > > It >> > > is not very long, however.", then RSA.Encrypt(MessageBytes, False) > fails >> > > with >> > > "Bad Length". I know that RSA is usually used for encrypting small > amounts >> > > of >> > > data, such as symmetric keys, but all the examples I have seen >> > > haven't >> > > mention this. Even Microsoft's Training Kit for their Microsoft > Certified >> > > Professional Exam 70-330 (Implementing Application Security) asks you > to >> > > build a program that encrypts entire files using RSA. Can anyone > provide a >> > > definite answer as to whether I can use RSA for what I am doing? > Thanks a >> > > lot >> > > for any response, as I have worked about 10 hours on this! >> > > >> > > dim message as string = "A longer string than an encryption >> > > key.......MessageText" >> > > dim unencryptedbytes() as byte = encoding.unicode.getbytes(message) >> > > dim RSA as new RSACryptoServiceProvider() >> > > RSA.FromXMLString(MyPrivateKey) >> > > dim encrypted() as byte = rsa.encrypt(unencryptedbytes, false) >> > > 'Errors >> > > here >> > > >> > > >> > > Joseph MCAD >> > > >> > > >> > >> > >> > > Not sure I understand you completely. If I read the post correctly, he
wants to encrypt some data on the client and send to some server. The server will have the private key to decrypt the key and iv. This is a normal way to do this type of thing. If he wants other, then need some more detail. Cheers. Show quote "Cantelmo Software" <i***@cantelmosoftware.com> wrote in message http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityCryptographyRSACryptoServiceProviderClassEncryptTopic.aspnews:uf7sKEGLFHA.3420@tk2msftngp13.phx.gbl... > Hi William, > if encrypt the simmetric-key with rsa public-key means that the customer > must have the private-key for the decrypt! > > this goes well in the normal documents (generic data) but *not* for the > applications (absolutely no!) why is possible to gain the public-key from > that private-key! > > in the software applications (as an example in the generation of a serial > number) it must be used rsa to the contrary. encrypt with the private key > and decrypt with that public-key. in this way I have only the certainty that > is *not possible* to make a keygen why the private-key lacks! > > best regards, > Marcello > www.cantelmosoftware.com > > "William Stacey [MVP]" <staceywREM***@mvps.org> ha scritto nel messaggio > news:uE7xfNCLFHA.2604@TK2MSFTNGP10.phx.gbl... > >I would not break into pieces to do rsa encryption. Just use Rijndael > > encryption. Use something like so: > > > > public class Doc > > { > > public byte[] Key; > > public byte[] IV; > > public byte[] Data > > } > > > > Then just create a Rijndael object that will have a new random key and iv. > > Encrypt your all your data using rij (say maybe an xml doc with all your > > textbox fields as elements) and store in Data. Then encrypt your key and > > iv > > using the public RSA key. Then just serialize the Doc class above using > > XmlSerializer into an Xml string and send to the receiver. Receiver does > > the reverse to get the data. No clear encryption key stored anywhere and > > each new run will have different key and iv. hth. > > > > -- > > William Stacey, MVP > > http://mvp.support.microsoft.com > > > > "Joseph MCAD" <JosephM***@discussions.microsoft.com> wrote in message > > news:5E4D3B47-B809-43A3-A8AC-D7E461BB5E61@microsoft.com... > >> > >> March 18, 2005 > >> > >> Thanks! I have looked for a very long time for those byte length > >> numbers! One problem though. :( If I am right, > > Encoding.Unicode.Getbytes() > >> converts each character to two bytes. That means that I cannot evenly > > feed > >> the bytes to RSA without splitting characters. Will this be a problem, > >> and > > am > >> I right that .GetBytes() converts chars to two bytes? Also do you know of > > a > >> way to split the UnEncrypted() byte array into blocks of 127? Right now, > >> I > >> have tried to input the message into a stringreader and then read back > > blocks > >> of 50 chars at a time. I then convert the block of chars to bytes and > >> feed > >> the block of bytes to the encryptor. This works, but I for some reason > > cannot > >> decrypt it. (I just realized that I encrypted using the private key and > > then > >> decrypted using the private key. Do I have to create another rsa object > > with > >> JUST the public key, or can I decrypt using the same RSA since it has > >> both > >> the private and public key?) I guess I am just really confused and I > > Really > >> Appreciate your help! > >> > >> > >> Joseph MCAD > >> > >> > >> > >> "Cantelmo Software" wrote: > >> > >> > Hi Joseph MCAD, > >> > the size limit is: 128-11=117 bytes for PKCS#1 v 1.5 padding. output is > >> > always 128 byte > >> > > >> > other details: > >> > > > Show quote > >> > > >> > HTH > >> > Marcello > >> > www.cantelmosoftware.com > >> > > >> > try my Goliath.NET obfuscator (pre-release version) & send me your > > opinion > >> > ;-) > >> > http://xoomer.virgilio.it/cantelmosoftware/net/TryMe.zip > >> > > >> > > >> > "Joseph MCAD" <JosephM***@discussions.microsoft.com> ha scritto nel > >> > messaggio news:4CD6D9DF-D97A-444C-81D5-7FD2C57FFD21@microsoft.com... > >> > > > >> > > March 18, 2005 > >> > > > >> > > I am trying to encrypt messages typed in a textbox by encrypting > > them > >> > > using RSACryptoServiceProvider. If the text is shorter than about 1/2 > > a > >> > > sentence, then it works fine. If it is longer, say: "This is my > > message. > >> > > It > >> > > is not very long, however.", then RSA.Encrypt(MessageBytes, False) > > fails > >> > > with > >> > > "Bad Length". I know that RSA is usually used for encrypting small > > amounts > >> > > of > >> > > data, such as symmetric keys, but all the examples I have seen > >> > > haven't > >> > > mention this. Even Microsoft's Training Kit for their Microsoft > > Certified > >> > > Professional Exam 70-330 (Implementing Application Security) asks you > > to > >> > > build a program that encrypts entire files using RSA. Can anyone > > provide a > >> > > definite answer as to whether I can use RSA for what I am doing? > > Thanks a > >> > > lot > >> > > for any response, as I have worked about 10 hours on this! > >> > > > >> > > dim message as string = "A longer string than an encryption > >> > > key.......MessageText" > >> > > dim unencryptedbytes() as byte = encoding.unicode.getbytes(message) > >> > > dim RSA as new RSACryptoServiceProvider() > >> > > RSA.FromXMLString(MyPrivateKey) > >> > > dim encrypted() as byte = rsa.encrypt(unencryptedbytes, false) > >> > > 'Errors > >> > > here > >> > > > >> > > > >> > > Joseph MCAD > >> > > > >> > > > >> > > >> > > >> > > > > > |
|||||||||||||||||||||||