Results 1 to 29 of 29

Thread: Add Powerful Encryption To Your Visual Basic Programs

Hybrid View

  1. #1
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Add Powerful Encryption To Your Visual Basic Programs

    Note: This doesn't run under Windows 2000 (with up to date service packs)

    I compiled the project, and it didn't run. It works fine under XP Home.

    Just found this, and it DOES work on both platforms. I don't know why.

    Code:
    Option Explicit 
    
    Dim sSecretData
    sSecretData = "Here is some very secret data." 
    
    ' Build up the key
    Dim wshNetwork, sComputerName
    Set wshNetwork = WScript.CreateObject("WScript.Network") 
    sComputerName = wshNetwork.ComputerName
    
    Dim capEData
    Set capEData = CreateObject("CAPICOM.EncryptedData")
    
    capEData.Algorithm = 3 'Use 3DES
    capEData.SetSecret sComputerName 
    capEData.Content = sSecretData
    
    Dim sCipherText
    sCipherText = capEData.Encrypt
    
    capEData.Algorithm = 3
    capEData.SetSecret sComputerName 
    capEData.Decrypt sCipherText
    
    Dim sPlainText
    sPlainText = capEData.Content 
    
    MsgBox "Original data: " & sSecretData & chr(13) _ 
      & "Encrypted data: " & sCipherText & chr(13) _ 
      & "Recoverd data: " & sPlainText
    Last edited by dglienna; Jan 7th, 2005 at 01:36 AM.

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Resolved Re: Add Powerful Encryption To Your Visual Basic Programs

    I'm hoping that 3DES is the missing key here. Testing it out.


    Hot-DAMN. Wasted a whole day when it was something so simple.

    EVERYBODY. DO USE 3DES encryption if you want it to work accross platforms.
    Last edited by dglienna; Jan 7th, 2005 at 01:52 AM.

  3. #3

    Thread Starter
    Hyperactive Member Maven's Avatar
    Join Date
    Feb 2003
    Location
    Greeneville, TN
    Posts
    322

    Re: Add Powerful Encryption To Your Visual Basic Programs

    Quote Originally Posted by dglienna
    I'm hoping that 3DES is the missing key here. Testing it out.


    Hot-DAMN. Wasted a whole day when it was something so simple.

    EVERYBODY. DO USE 3DES encryption if you want it to work accross platforms.
    That com is just a wrapper around the windows crypto API. Different versions of windows support different key sizes, different ciphers, etc.
    Education is an admirable thing, but it is well to remember from time to time that nothing that is worth knowing can be taught. - Oscar Wilde

  4. #4
    Junior Member
    Join Date
    Jun 2002
    Location
    Kentucky
    Posts
    21

    Request for an example using...

    Could you show a simple example of using CAPICOM to encode a binary file, such as myprog.exe or myarchive.zip, rather than a string?

  5. #5

    Thread Starter
    Hyperactive Member Maven's Avatar
    Join Date
    Feb 2003
    Location
    Greeneville, TN
    Posts
    322

    Re: Add Powerful Encryption To Your Visual Basic Programs

    It should work the same way with binary. Just make sure you use byte data types instead of string. If you want the results stored as binary instead of base64 then you need to use CAPICOM_ENCODE_BINARY.


    While I'm here, this is how you hash data:
    Dim x As New HashedData
    x.Algorithm = CAPICOM_HASH_ALGORITHM_MD5
    x.Hash ("Hash This")
    Text1.Text = x.Value
    Education is an admirable thing, but it is well to remember from time to time that nothing that is worth knowing can be taught. - Oscar Wilde

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Add Powerful Encryption To Your Visual Basic Programs

    isn't there a way to encrypt a whole file at once, like an attachment to an email? I got that from the website, but they didn't give any examples. If you wanted to encrypt an .exe, you'd have to read the binary file, and encrypt it by encrypting each byte, or what?

  7. #7

    Thread Starter
    Hyperactive Member Maven's Avatar
    Join Date
    Feb 2003
    Location
    Greeneville, TN
    Posts
    322

    Re: Add Powerful Encryption To Your Visual Basic Programs

    Quote Originally Posted by dglienna
    isn't there a way to encrypt a whole file at once, like an attachment to an email? I got that from the website, but they didn't give any examples. If you wanted to encrypt an .exe, you'd have to read the binary file, and encrypt it by encrypting each byte, or what?
    I'm not aware of any functions for encryption a file. Would definitly make life a lot simpler though wouldn't it? You would do it just like a string with the exception that it would be a byte array instead of a string array. Just make sure when you read the file, you do it as binary and not as string (text).


    Later on I may write a decent cipher library but as for right now I'm working long ass hours and have very little time =/
    Education is an admirable thing, but it is well to remember from time to time that nothing that is worth knowing can be taught. - Oscar Wilde

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