×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Read Encrypted Text File

Read Encrypted Text File

Read Encrypted Text File

(OP)
Hi,

Not sure if this is the right area, but I'm trying to write some code to open/read from an encrypted text file. So far I have:

Option Explicit

'File Stream Objects
Private objFSO As Object
Private objPasswordFile As Object

'Strings

Public strAdminPassword As String
Private Const strFilePath As String = "My Dir"

Public Sub GetAdminPassword()



Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FileExists(strFilePath) Then

Set objPasswordFile = objFSO.OpenTextFile(strFilePath, 1)
strAdminPassword = objPasswordFile.ReadLine
objPasswordFile.Close
Else

MsgBox "File Error", vbOKOnly, "Error"
End
End If

Set objFSO = Nothing
Set objPasswordFile = Nothing
End Sub

This code works fine since the only line/item in the file is the password, but now I'd like to add some encryption to this ... I'm wondering if someone can assist with a link or something since I'm unable to find anything related to this.

The reason for this is unfortunately we have many separate macros (sage VBA) which require the admin login and password and we've had to hardcode this in hundreds of spots and I'm trying to build a deployment structure so the file can be overwritten as need to change the password and remove the hardcoding from the macro, but the users would have access to the file location as well so we can't have them opening it and seeing the admin password.

RE: Read Encrypted Text File

The only thing you have to know is that there are no rules to encryption. There are loads of encryption methods. Presumably you need 2 way encryption.

You could use one of the common methods like DES, AES, blowfish, RSA or make up your own. You need a 2-way one. Some of these have a public and private key, which you will need to store somewhere to encrypt/decrypt. How you encrypt stuff is entirely up to you - remember - there are no rules.

Depends how knowledgeable your people are. If the people are non-programmers (they know about every single icon/menu option in excel but nothing about VBA or any form of programming), you could use a simple Caesar cipher. You don't have to say it is a Caesar cipher - you could say it is RSA or something like that (there are no rules - you can lie about it). You don't have to worry if an article says that someone has managed to crack the RSA cipher in 3 hours - yours is just a Caesar cipher which everyone thinks is RSA.

Just have your encrypted password in say characters 10 to 17 and the rest of it can be anything you like. It doesn't even have to be sequential.

Another method, you can have the password in plain sight - just jumble the characters around. The one in the password file can be

CODE

thefiveboxingwizardsjumpquickly
123456789012345678901234567890 

It doesn't even have to be in English. Say it is a 5 letter password - characters 17, 8, 28, 19, 3 - abcde. Your code can just pick out those characters for the password in your code. They don't have to be unique and you can pick the same letter as many times as you like. It doesn't have to be a mathematical algorithm (like RSA etc).

Of course, the encryption specialists (yes - there are such people, I once worked in a department of 50 with 20 encryption specialists) will tell you that to have your password in plain sight is a bad idea but given that that is what is in your file, and nobody knows which characters you are picking, how would anyone know what the password is other than it is made up of some of those letters. They don't even know how long it is.

RE: Read Encrypted Text File

>make up your own

Oh, let's not, please

And the whole point of public key encryption is that the public key can quite happily be in plain sight.

RE: Read Encrypted Text File

Here is a thread with code examples illustrating hashing and encryption: thread222-535644: MD5 encryption

Note that for a long time Windows also shipped with an ActiveX dll, CAPICOM, which made this all rather easy. Sadly more recent versions have deprecated it in favour of .Nets cryptography assemblies. However, it IS still downloadable from Microsoft and my example of how to use that can be found here: thread222-1548222: password encryption - vb6

RE: Read Encrypted Text File

Did anything above help at all?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close