Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>(EDIT: I've been assuming you want to both <em>encrypt</em> a string, and then <em>encode</em> the result as base64, always ending up with the same output length. It would help if you could clarify the question to confirm this or explain what you <em>do</em> want if this isn't it.)</p> <p>Well, there's a pretty simply algorithm which would work given any encryption scheme which always encrypts an input of a fixed length to an output of a fixed length (and there are plenty of those):</p> <ul> <li>Encode the string as binary using UTF-16 (which will always give the same byte array length for the same string input)</li> <li>Pad the binary data to 32 bytes (i.e. the maximum size) using random data</li> <li>Add an extra byte at the end (or start) indicating the original length</li> <li>Encrypt the binary data (which will always be 33 bytes)</li> <li>Convert the result to base64 using <code>Convert.ToBase64String</code></li> </ul> <p>To decrypt, simply reverse the process:</p> <ul> <li>Convert the base64 text to the encrypted binary data using <code>Convert.FromBase64String</code></li> <li>Decrypt the binary data (back to "plaintext" binary)</li> <li>Find the length from the first or last byte</li> <li>Decode the relevant section of the plaintext binary as UTF-16 text</li> </ul> <p>(Use MSDN to find details of each step, and feel free to ask for help in a specific part. Your choice of encryption algorithm will depend on what you're trying to do, and I'm no expert on that, I'm afraid.)</p> <p>EDIT: If you only need a hash, then other questions come into play. Would you always want the same string to end up being hashed <em>to</em> the same string? That's typically desirable for hashing but not encryption.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload