balrom
asked on
AnsiReplaceString DON'T WORK: Replace some characters in a String with bynary contents
Hi Experts, i have to encrypt a string that contains some plain text.
After encryption the contents of the string have any kind of character.
In this resulting string, i need to replace some characters, for example "|" to "\|".
I was trying to do this with AnsiReplaceString supplied by delphi (version 7), but it not seems to work (no replace is made).
Have you any idea?
Best regards
After encryption the contents of the string have any kind of character.
In this resulting string, i need to replace some characters, for example "|" to "\|".
I was trying to do this with AnsiReplaceString supplied by delphi (version 7), but it not seems to work (no replace is made).
Have you any idea?
Best regards
hello balrom, , I do not know the encryption that you use, but many encryptions DO NOT encrypt ANSII text to ANSII text, but will have "have any kind of character" which you discribe (acually there are NO CHARACTERS in it at all, since it is now digital data, not text data). . . almost all of the String functions will STOP their procedure for scanning through a strng, whenever they get to a Byte in the string with a value of zero, #0,, which is the famous Null Character, so if your encyipted text has any zero value bytes in it, then the AnsiReplaceString may not work with it. . .
I would wounder why you would need to do any AnsiReplaceString kind of thing after you encrypt it, , shouldn't you do that before you encrytp it? ?
I would wounder why you would need to do any AnsiReplaceString kind of thing after you encrypt it, , shouldn't you do that before you encrytp it? ?
All Ansi functions handle MCBS strings so you get problems with your encrypted strings.
A peek at the sources reveals that AnsiReplaceStr uses AnsiPos which handles MCBS.
A peek at the sources reveals that AnsiReplaceStr uses AnsiPos which handles MCBS.
ASKER
Thank you for your replies.
gwalkeriq: I don'w want to use base64 encoding, it increase the size of final string (about 1/3).
Slick812: I need to do the replace after enctyption.
robert_marquardt: If Ansi functions don't work on this type of content, it there an alternative function?
Best regards
gwalkeriq: I don'w want to use base64 encoding, it increase the size of final string (about 1/3).
Slick812: I need to do the replace after enctyption.
robert_marquardt: If Ansi functions don't work on this type of content, it there an alternative function?
Best regards
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks carcotasu, a very nice set of fast functions...
I've tested it and works fine!!
I've tested it and works fine!!
Encoding Phase
1) Compress original string (optional)
2) Encrypt
3) base64 encode
Now is it safe to transmit, store, etc. the encoded data
Decoding Phase
1) base64 decode
2) decypt
3) uncompress (if compressed)
Look up base64 encoding/decoding and you will understand why this is used. Delphi source for base64 encoding is fairly easy to find too http://www.google.com/search?hl=en&q=base64+%22delphi+source%22&btnG=Google+Search