0

I am trying to build a web app that uses AES to encrypt strings. I store the encrypted strings in a file and decrypt it when needed again. But I need to add a delimiter to seperate encrypted strings from normal strings in the file. So naturally the delimiter would be some character that is not included in the AES output. So which characters could the delimiter be? I tried googling but could not find any satisfactorily results. Any code in JavaScript or PHP would be helpful

coderGtm
  • 91
  • 1
  • 10
  • 1
    Welcome to Stackoverflow. As you didn't tag any programming language it is very difficult to give any advice in code form (b.t.w. it is against ST rules to ask for code...). To answer your question in general: encode the output of AES encryption to Base64 and use ":" as delimiter - this character is widely used. – Michael Fehr Oct 23 '20 at 09:48
  • Ok....i didn't knew that...and thank you :-) – coderGtm Oct 23 '20 at 09:56
  • Use tag-based solutions is fine for you [How do you parse and process HTML/XML in PHP?](https://stackoverflow.com/q/3577641/1820553). LIke encrypted data here and it should be code in hex or base64... – kelalaka Oct 23 '20 at 10:02

1 Answers1

1

Input and output to crypto functions are normally byte arrays; you want to encode data. Good candidates are Hex or Base64. Both have well-defined character-sets.

clausc
  • 166
  • 6
  • Can you please show with a code as i did not get it very well – coderGtm Oct 23 '20 at 09:31
  • 2
    Your encrypted data can include and possible delimiter you choose. If you encode the raw bytes as Base64, then it will only include the 64 allowed Base64 characters: [A..Z, a..z, 0..9, +, /] That way you can safely use something like # or $ as a delimiter, basically any character that does not appear in the Base64 character set. – rossum Oct 23 '20 at 10:42