Equivalent of RSACryptoServiceProvider in Visual Basic 6.0
Hi,
I am trying to encrypt my private message using RSA algorithm.
I got RSACryptoServiceProvider namespace in C# .NET which do the same work. But I am looking for VB 6.0 equivalent of RSACryptoServiceProvider.
Actually I want to incorporate this code in Excel VBA for general use.
Can anybody help me on that???
Or else please tell me if there is any alternative to encrypt my private message using RSA algorithm (I don't have any option other than RSA as it is the basic requirement of my project )
Re: Equivalent of RSACryptoServiceProvider in Visual Basic 6.0
Thread moved to Office Development/VBA forum (note that the "VB Editor" in Office programs is actually VBA rather than VB, so the VB6 forum is not really apt)
Re: Equivalent of RSACryptoServiceProvider in Visual Basic 6.0
you can start by adding a reference to mscorlib and
vb Code:
Dim rsa As mscorlib.RSACryptoServiceProvider
Set rsa = New RSACryptoServiceProvider
Re: Equivalent of RSACryptoServiceProvider in Visual Basic 6.0
Hi, first of all thanks a lot for the response...
Somehow I managed to code the working example using RSACryptoServiceProvider.
I added reference of mscorlib.dll in the project. Following is the code:
Dim inputValue
inputValue = Text1.Text
Dim dataToEncrypt() As Byte
dataToEncrypt = StrConv(inputValue, vbFromUnicode)
Dim encryptedData() As Byte
Dim decryptedData() As Byte
'Create a new instance of RSACryptoServiceProvider
Dim rsa As New RSACryptoServiceProvider
Dim RSAPublicKeyInfo
Dim RSAPrivateKeyInfo
RSAPublicKeyInfo = "<RSAKeyValue><Modulus>vnevxCr1jHl8FY1sZ/TtjEtWtrPYA639dPUer+22/ZO9mBKWTp96xHrNNQfnqiYXcfDiAs74I5lAo3sQ91/iioph43rMvQcMxvX/QMlGSFhRH7GtcnHkaPJGVDrzBj0d7o7GpFv1P5Bg4GtK/5xYzRAllPCUa4oMVDlKthSofKc=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>"
RSAPrivateKeyInfo = "<RSAKeyValue><Modulus>vnevxCr1jHl8FY1sZ/TtjEtWtrPYA639dPUer+22/ZO9mBKWTp96xHrNNQfnqiYXcfDiAs74I5lAo3sQ91/iioph43rMvQcMxvX/QMlGSFhRH7GtcnHkaPJGVDrzBj0d7o7GpFv1P5Bg4GtK/5xYzRAllPCUa4oMVDlKthSofKc=</Modulus><Exponent>AQAB</Exponent><P>4Vm9Coxk+NZWrFaC+8NwFXSOgnB7w0+bFEuY5Mxc5lMhOnc6NaxIMnSm1QGZ++Y/TRrClqFQ/Blu+0E1TOTbqQ==</P><Q>2F9j7MH6NB2R2jQ0Ti7hov7ymIEJdAAN8yljTdYX0ycsGVtf+At3GmKGqmcibYokKjA9N90gaubanOdnrpdHzw==</Q><DP>L283RpgkzOg5GE+hhKMv3aRKNxS8SHFiQFRlW4vU5jqLXQYpv5CDJfO+BkovAoIFwxIl8ZUFOfuUi9i/Am+N+Q==</DP><DQ>LMkJyM6ZuEHKl6yoiuo/P9qfYhuLVlxQht0xNcIzqjv4b8MvCQtueqKcFxdD1AJ829KiSTbW5+mipEltd4DOlw==</DQ><InverseQ>2kfRazi4+V2KO8Y/eHwMAxoi1GGDX9wYyNEsiBKIpCBq+Tb/3hpWxWyTlDci0/AwdSNBjlMm/+N5URCTcmsaZw==</InverseQ><D>gVHgLDAC0mL1peiEzzyUQSox8RDAvRbYPR3kvQyIrzkthGAyX6WWhGrgg34fg/4i8wDbY47FGd6G7bi0N1GKDNyniJIhLXXUZsqD9ItYJd47ad7sL9ETiA7WHpBeq74WTnUplvP4W+r/RlU0Je4dsPzQhGtFQrWjCmCHN0VJQDE=</D></RSAKeyValue>"
rsa.FromXmlString (RSAPublicKeyInfo)
encryptedData = rsa.Encrypt(dataToEncrypt, False)
rsa.FromXmlString (RSAPrivateKeyInfo)
decryptedData = rsa.Decrypt(encryptedData, False)
MsgBox (StrConv(encryptedData, vbUnicode))
MsgBox (StrConv(decryptedData, vbUnicode))
This is doing both the encryption and decryption perfectly fine.
But according to my requirement, I am facing one more issue.
Actually I need to send the encrypted password to a webservice. This webservice is written in C# .NET. According to the code implementation in webService, I need to pass the encrypted password to the webservice. This webService will take care of decrypting my encrypted password and then it will validate my login credential.
As I told you earlier, that my code is doing both the encryption and decryption fine. But the webService takes the encrypted password in "base64Binary" format. Can I reform my encryption mechanism so that I can get a base64Binary format encrypted password???
What else can I do to resolve my problem???
Any help is highly appreciated... :)
Re: Equivalent of RSACryptoServiceProvider in Visual Basic 6.0
sorry i am all out of help on this one
checkout the codebank (vb6) for base 64 encoding, nearly any vb6 code will work in vba
Re: Equivalent of RSACryptoServiceProvider in Visual Basic 6.0
I'm not aware of any "standard" libraries you can reference in vba that will handle encoding and decoding from one base to another. Short of writing your own (I always say that haha), you'll have to get a 3rd party one. Here's one I found by searching google for "base64 activex"
http://www.brothersoft.com/base64-en...ry-163699.html
It really doesn't matter what language the webservice is written in.
If you happen to find a good library for this, please post back here.
Re: Equivalent of RSACryptoServiceProvider in Visual Basic 6.0
I have already mentioned in my thread that I am able to get RSACryptoServiceProvider with Visual Basic 6.0 after adding reference to mscorlib.dll to my project. But I am not able to get RSACryptoServiceProvider in VBA even after adding the reference of mscorlib.dll
Can anybody help me on that???
Till the time, I am not able to get the VBA equivalent of UTF8 Encoding...
I need some help on that as well... :)
Re: Equivalent of RSACryptoServiceProvider in Visual Basic 6.0
Quote:
Till the time, I am not able to get the VBA equivalent of UTF8 Encoding...
Interesting Read...
Re: Equivalent of RSACryptoServiceProvider in Visual Basic 6.0
Quote:
I have already mentioned in my thread that I am able to get RSACryptoServiceProvider with Visual Basic 6.0 after adding reference to mscorlib.dll to my project. But I am not able to get RSACryptoServiceProvider in VBA even after adding the reference of mscorlib.dll
Can anybody help me on that???
create an activex dll in vb6 create an object to that from vba, i am suprised it does not work invba if it works in vb6, try it in a class module
Re: Equivalent of RSACryptoServiceProvider in Visual Basic 6.0
I can't fine mscorlib.dll in ANY folder on my computer. Please help.
The OS I'm using is Windows 7 Home Premium x64 with SP1.
Re: Equivalent of RSACryptoServiceProvider in Visual Basic 6.0
Convert bytes to base64 then it will work for c# code also.
http://www.nonhostile.com/howto-enco...base64-vb6.asp
This link will help you.