-4

I have two strings, that are encrypted with a code from accepted answer from this link. I want connect them in some other string, which will be simple to decrypt back to the two original encrypted strings. I think that:

encrypted_string_1 + encryptedstring_2

is a bad idea.

Community
  • 1
  • 1
DamianOS.MP5
  • 252
  • 1
  • 2
  • 12
  • 2
    Your question is unclear. What are you trying to do exactly? You're right that concatenating them while encrypted is a bad idea. – Equalsk Oct 18 '16 at 15:07
  • The code in the link shows how to decrypt. So what is the real problem? – Ňɏssa Pøngjǣrdenlarp Oct 18 '16 at 15:07
  • 1
    Even if you have just two *plain* texts, say `"AB"` and `"C"` and you've combined them into `"ABC"`, how can you'll split them back? Since `""` and`"ABC"`, `"A"` and `"BC"`, `"AB"` and `"C"`, `"ABC"` and `""` are possible – Dmitry Bychenko Oct 18 '16 at 15:09
  • 1
    find a delimiter - like `encrypted_string_1 + '|' + encrypted_string_2` – Benj Oct 18 '16 at 15:10
  • i think that he wants to dectyrp both strings at once (merge them, decrypt and than split). in post of encryption types (aldo the one used in your link) you cannot do that. each encrypted string is atomic and should be decrypted separetly – Misiakw Oct 18 '16 at 15:11
  • 1
    You can't combine encrypted string unless you have a character count to allow you to separate the two string before de-crypting. – jdweng Oct 18 '16 at 15:12
  • 1
    Why do you need to join two encrypted strings together? Is it to store them somewhere? It smells like something else is wrong and this is a workaround to the problem. – Equalsk Oct 18 '16 at 15:13
  • W̶e̶ ̶k̶n̶o̶w̶ ̶y̶o̶u̶ ̶w̶a̶n̶t̶ ̶t̶o̶ ̶c̶o̶m̶b̶i̶n̶e̶ ̶t̶h̶e̶ ̶t̶w̶o̶ ̶s̶t̶r̶i̶n̶g̶s̶,̶ ̶b̶u̶t̶ ̶w̶h̶y̶?̶ ̶W̶h̶y̶ ̶c̶a̶n̶'̶t̶ ̶y̶o̶u̶ ̶l̶e̶a̶v̶e̶ ̶t̶h̶e̶m̶ ̶s̶e̶p̶a̶r̶a̶t̶e̶?̶ ̶I̶f̶ ̶y̶o̶u̶ ̶c̶l̶e̶a̶r̶l̶y̶ ̶e̶x̶p̶l̶a̶i̶n̶ ̶w̶h̶a̶t̶ ̶y̶o̶u̶'̶r̶e̶ ̶t̶r̶y̶i̶n̶g̶ ̶t̶o̶ ̶d̶o̶ ̶w̶e̶ ̶m̶i̶g̶h̶t̶ ̶b̶e̶ ̶a̶b̶l̶e̶ ̶t̶o̶ ̶h̶e̶l̶p̶.̶ ̶A̶s̶ ̶i̶t̶ ̶s̶t̶a̶n̶d̶s̶ ̶i̶t̶'̶s̶ ̶s̶t̶i̶l̶l̶ ̶p̶r̶e̶t̶t̶y̶ ̶u̶n̶c̶l̶e̶a̶r̶ ̶w̶h̶a̶t̶ ̶y̶o̶u̶'̶r̶e̶ ̶d̶o̶i̶n̶g̶ ̶h̶e̶r̶e̶.̶ While your link clears the situation up a little I'm sure it would be considered 'off topic' here on StackOverflow as too broad. – Equalsk Oct 18 '16 at 15:20

1 Answers1

0

If you can identify a separator character (e.g. '~') that is never produced as output by the encrypt method, then you can use that:

const char sep = '~';
string combined = encrypted_string_1 + sep + encryptedstring_2;

And then split it later:

string[] parts = combined.Split(sep);

which can then be decrypted.

Edit:
The output of Encrypt() is already base-64 encoded, which produces[1]...

uppercase characters "A" to "Z", lowercase characters "a" to "z", numerals "0" to "9", and symbols "+" and "/". The valueless character, "=", is used for trailing padding.

So any other character can be used as a separator.

[1] see https://msdn.microsoft.com/en-us/library/dhx0d524(v=vs.100).aspx

Peter B
  • 21,067
  • 5
  • 28
  • 63