Decrypt encrypted column in SQL Server which is non-human readable format - sql

Recently I have imported some production data into a table. In that table, some columns are encrypted as non-human readable format. For ex: 'Õ;Q€Kùu'.
I have tried to convert it to human readable format liket his:
SELECT CONVERT(NVARCHAR(MAX), 'Õ;Q€Kùu')
But it didn't return the correct output. Is it possible to convert the non-human readable data into human readable format?

you cannot decrypt that column. You should know encryption key. It should be in software code. However there are some MD5 decrypt sites they have encryption key database it may help.
Try search google with encrypt MD5

Related

Can i search encrypted data in Laravel

In the Laravel, I have encrypted records in my table and I would like to search these records.
The problem occur when I do search and encrypt again my search term, it encrypts it again generating random string.

How to select SHA1 hash values correctly?

I need to extract SHA1 Passwords from a Microsoft SQL Server database in order to use them in an external system.
When I do a simple select query for a known password, I get this result (password is "password"):
"{SHA1=5b9febc2d7429c8f2002721484a71a84c12730c7}"
But it should be 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8.
Any idea how to select it to get the expected value 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8?
SHA1 hashing is done on bytes, not on characters, therefore it's important to make sure that the conversion from characters to bytes is done with an agreed upon encoding.
5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8 is the SHA1 hash of password encoded in ASCII/UTF-8.
5b9febc2d7429c8f2002721484a71a84c12730c7 is the SHA1 hash of password encoded in UTF-16-BE.
To fix this, pick one encoding, and change whatever code is using the other encoding to match.

How do you do a PostgreSQL fulltext search on encoded or encrypted data?

For various reasons that don't matter here we are storing chunks of text in either an encrypted or base64 encoded format in PostgreSQL. However, we want to be able to use PostgreSQL's fulltext search to find and return data which in its unencrypted/decoded form matches a search query.
How would one go about accomplishing this? I've seen other posts mention the ability to build the tsvector values before sending data to the database, but I was hoping there would be something available on the Postgres end of things (at least for the base64 text).
Encrypted values
For encrypted values you can't. Even if you created the tsvector client-side, the tsvector would contain a form of the encrypted text so it wouldn't be acceptable for most applications. Observe:
regress=> SELECT to_tsvector('my secret password is CandyStrip3r');
to_tsvector
------------------------------------------
'candystrip3r':5 'password':3 'secret':2
(1 row)
... whoops. It doesn't matter if you create that value client side instead of using to_tsvector, it'll still have your password in cleartext. You could encrypt the tsvector, but then you couldn't use it for fulltext seach.
Sure, given the encrypted value:
CREATE EXTENSION pgcrypto;
regress=> SELECT encrypt( convert_to('my s3kritPassw1rd','utf-8'), '\xdeadbeef', 'aes');
encrypt
--------------------------------------------------------------------
\x10441717bfc843677d2b76ac357a55ac5566ffe737105332552f98c2338480ff
(1 row)
you can (but shouldn't) do something like this:
regress=> SELECT to_tsvector( convert_from(decrypt('\x10441717bfc843677d2b76ac357a55ac5566ffe737105332552f98c2338480ff', '\xdeadbeef', 'aes'), 'utf-8') );
to_tsvector
--------------------
's3kritpassw1rd':2
(1 row)
... but if the problems with that aren't immediately obvious after scrolling right in the code display box then you should really be getting somebody else to do your security design for you ;-)
There's been tons of research on ways to perform operations on encrypted values without decrypting them, like adding two encrypted numbers together to produce a result that's encrypted with the same key, so the process doing the adding doesn't need the ability to decrypt the inputs in order to get the output. It's possible some of this could be applied to fts - but it's way beyond my level of expertise in the area and likely to be horribly inefficient and/or cryptographically weak anyway.
Base64-encoded values
For base64 you decode the base64 before feeding it into to_tsvector. Because decode returns a bytea and you know the encoded data is text you need to use convert_from to decode the bytea into text in the database encoding, eg:
regress=> SELECT encode(convert_to('some text to search','utf-8'), 'base64');
encode
------------------------------
c29tZSB0ZXh0IHRvIHNlYXJjaA==
(1 row)
regress=> SELECT to_tsvector(convert_from( decode('c29tZSB0ZXh0IHRvIHNlYXJjaA==', 'base64'), getdatabaseencoding() ));
to_tsvector
---------------------
'search':4 'text':2
(1 row)
In this case I've used the database encoding as the input to convert_from, but you need to make sure you use the encoding that the underlying base64 encoded text was in. Your application is responsible for getting this right. I suggest either storing the encoding in a 2nd column or ensuring that your application always encodes the text as utf-8 before applying base64 encoding.

Using hsqldb as a key-value store

I would like to use hsqldb as a simple key-value store, where both the key and the value are strings.
The value would be a JSON of some data, say no more than 10K in size.
The type of the value column is LONGVARCHAR.
I would like to know whether this type is suitable for this purpose.
P.S.
A bit of background. We wanted to use MongoDB or CouchDB, but the latest MongoDB does not support Windows XP and the latest CouchDB does not support Windows 32 bits, both of which is a requirement. Using a DB like Cassandra seems like an enormous overkill in our case.
If the values are already in the UTF-8 or other 8 bit encoding form, you can use BLOB or VARBINARY. Otherwise, use CLOB or VARCHAR for Unicode characters. Both forms are suitable for up to 10K values. Note LONGVARCHAR is simply a long VARCHAR.
If speed of access is essential, you can test with both types and decide which one is the best for your data. The same access API can be used for BLOB/VARBINARY or CLOB/VARCHAR when the values are relatively small (10k).

What is the smallest way to store a UUID that is human readable?

What is the smallest way to store a UUID that is human readable and widely database compatible?
I am thinking a char array of some sort using hex values?
As common approach, i think that encoding the binary data (16 bytes) as Base64 could be what you want.
Use Base-85 encoding to store the UUID as 20 US-ASCII characters.
You might find the latest podcast relevant:
http://itc.conversationsnetwork.org/shows/detail4087.html
Database-wide unique-yet-simple identifiers in SQL Server
You want Base64 if it is going to be in any kind of computer representation. Base85 if you can figure out a way around putting it in a URL. See: http://en.wikipedia.org/wiki/Base64 and http://en.wikipedia.org/wiki/Ascii85