PB doesn't have any encryption libs built in, what algorithm are you wanting to use? or what level of encryption? How serious is this?
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
I am also a sufficient level of encryption simply by perhaps 64 to 128 bits, the important one when it goes to open the file does not understand anything of reading
If you just need something simple, I would suggest an aglorithm like XTEA, it's fast, not a lot of code and seems to be secure from what I read. If I had secrets from the NSA I'm not sure I'd use it but I guess that's not were you are coming from
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Procedure XOrCrypt(*Buffer,Len.l,Key$)
;just some weird and powerful(?) xor encryption algorithm by JLC
Protected i, Byte.b, KeyByte.b
Protected KeyLength = Len(Key$), KeyPos
For i=0 To Len-1
Byte = PeekB(*Buffer+i)
KeyByte = PeekB(@Key$+KeyPos)
;PeekB(*Buffer+i) ! PeekB(@Key$+KeyPos) ! Len ! i
Byte ! KeyByte ! Len ! i ! KeyLength ;xor the shit
PokeB(*Buffer+i,Byte)
KeyPos + 1
If KeyPos > KeyLength
KeyPos = 0
EndIf
Next
EndProcedure
String$ = "the string to be encrypted"
Length = Len(String$)
XOrCrypt(@String$,Length,"key of whatever length") ;encrypt
Debug String$ ;if it looks cut that's because a null-char. terminates it
XOrCrypt(@String$,Length,"key of whatever length") ;decrypt
Debug String$
I like logic, hence I dislike humans but love computers.
pbprog wrote:and is a text file or ini file ... which is always text ..
I hope that I can then using GetIniKey read from memory .....
otherwise how do I interpret ini files from memory as GetIniKey?
A simple thing would be to store the decrypted file in the temp directory and then read it using the normal commands. PB has commands for this btw, look in help file under "Preference", OpenPreferences and then ReadPreferenceString will probably help you.
If you REALLY need to do this directly in memory I'm not sure if you can get any commands to do that. Maybe make some commands yourself to do this (what I would do). Or see if anyone else can help you.
I like logic, hence I dislike humans but love computers.
Procedure XOrCrypt(*Buffer,Len.l,Key$)
;just some weird and powerful(?) xor encryption algorithm by JLC
Protected i, Byte.b, KeyByte.b
Protected KeyLength = Len(Key$), KeyPos
For i=0 To Len-1
Byte = PeekB(*Buffer+i)
KeyByte = PeekB(@Key$+KeyPos)
;PeekB(*Buffer+i) ! PeekB(@Key$+KeyPos) ! Len ! i
Byte ! KeyByte ! Len ! i ! KeyLength ;xor the shit
PokeB(*Buffer+i,Byte)
KeyPos + 1
If KeyPos > KeyLength
KeyPos = 0
EndIf
Next
EndProcedure
String$ = "the string to be encrypted"
Length = Len(String$)
XOrCrypt(@String$,Length,"key of whatever length") ;encrypt
Debug String$ ;if it looks cut that's because a null-char. terminates it
XOrCrypt(@String$,Length,"key of whatever length") ;decrypt
Debug String$
however, thanks to 'help ... and all the technical support ....
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
pbprog wrote:this example and for strings only how to encrypt and decrypt an entire file?
If your file is text-only, you can read the entire file into a string and then do the en-/decrypting.
No matter what the file is you can read it into a memory buffer and use my procedure on it, you only need to know the memory address and length.
Example:
But for large files reading it into memory is a bad idea, so the code should be modified to work with the content of the file instead then. Could probably do something like this and then "cut and paste" code from the other procedure: