<p>We have a situation in our product where for a long time some data has been stored in the application's database as SQL string (choice of MS SQL server or sybase SQL anywhere) which was encrypted via the Windows API function <a href="http://msdn.microsoft.com/en-us/library/aa379924.aspx" rel="nofollow noreferrer">CryptEncrypt.</a>  (direct and de-cryptable)</p>
<p>The problem is that CryptEncrypt can produce NULL's in the output, meaning that when it's stored in the database, the string manipulations will at some point truncate the CipherText.</p>
<p>Ideally we'd like to use an algo that will produce CipherText that doesn't contain NULLs as that will cause the least amount of change to the existing databases (changing a column from string to binary and code to deal with binary instead of strings) and just decrypt existing data and re-encrypt with the new algorithm at database upgrade time.</p>
<p>The algorithm doesn't need to be the most secure, as the database is already in a reasonably secure environment (not an open network / the inter-webs) but does need to be better than ROT13 (which I can almost decrypt in my head now!)</p>
<p>edit: btw, any particular reason for changing ciphertext to cyphertext? ciphertext seems more widely used...</p>

[{'answer_id': 17683, 'author': 'OJ.', 'author_id': 611, 'author_profile': 'https://Stackoverflow.com/users/611', 'pm_score': 3, 'selected': True, 'text': '<p>Any semi-decent algorithm will end up with a strong chance of generating a NULL value somewhere in the resulting ciphertext.</p>\n\n<p>Why not do something like <a href="http://en.wikipedia.org/wiki/Base64" rel="nofollow noreferrer">base-64 encode</a> your resulting binary blob before persisting to the DB? (<a href="http://synesis.com.au/software/b64.html" rel="nofollow noreferrer">sample implementation in C++</a>).</p>\n'}, {'answer_id': 17699, 'author': 'geocoin', 'author_id': 379, 'author_profile': 'https://Stackoverflow.com/users/379', 'pm_score': 0, 'selected': False, 'text': "<p>That's an interesting route OJ.\nWe're looking at the feasability of a non-reversable method (still making sure we don't explicitly retrieve the data to decrypt) e.g. just store a Hash to compare on a submission</p>\n"}, {'answer_id': 17720, 'author': 'Greg Hewgill', 'author_id': 893, 'author_profile': 'https://Stackoverflow.com/users/893', 'pm_score': 1, 'selected': False, 'text': '<p>Storing a hash is a good idea. However, please definitely read Jeff\'s <a href="http://www.codinghorror.com/blog/archives/000953.html" rel="nofollow noreferrer">You\'re Probably Storing Passwords Incorrectly</a>.</p>\n'}, {'answer_id': 17750, 'author': 'geocoin', 'author_id': 379, 'author_profile': 'https://Stackoverflow.com/users/379', 'pm_score': 0, 'selected': False, 'text': '<p>It seems that the developer handling this is going to wrap the existing encryption with <a href="http://www.yenc.org" rel="nofollow noreferrer">yEnc</a> to preserve the table integrity as the data needs to be retrievable, and this save all that messy mucking about with infinite-improbab.... uhhh changing column types on entrenched installations.\nCheers Guys</p>\n'}]
['https://Stackoverflow.com/questions/17670', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/379/']