Results 1 to 11 of 11

Thread: Equivalent of RSACryptoServiceProvider in Visual Basic 6.0

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    5

    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 )

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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)

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Equivalent of RSACryptoServiceProvider in Visual Basic 6.0

    you can start by adding a reference to mscorlib and
    vb Code:
    1. Dim rsa As mscorlib.RSACryptoServiceProvider
    2. Set rsa = New RSACryptoServiceProvider
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    5

    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...

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    577

    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.

  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    5

    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...

  8. #8
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Equivalent of RSACryptoServiceProvider in Visual Basic 6.0

    Till the time, I am not able to get the VBA equivalent of UTF8 Encoding...
    Interesting Read...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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???
    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
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  10. #10
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,238

    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.

  11. #11
    New Member
    Join Date
    Jan 2014
    Posts
    1

    Cool 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width