0
votes

I'm looking for a library for encrypting and decrypting a string which provides the following properties:

  • Using an encryption mode block or stream, besides that I'm indifferent towards the algorithm.
  • Should support a key with small length, small enough to enable known text cipher attack.
  • Preferably should be able to take care of low level cryptography issues such as padding decisions.

For example:

string Encrypt(int key, string messageToBeEncrypted) // returns cipher
string Decrypt(int key, string messageToBeDecrypted) // returns message
3
mcrypt is very easy to use. Doesn't have padding, but it's trivial to write a PKCS padder. - Kerrek SB
There was some library that Google created that was designed to be extremely simple to use. I lost the link though. - Omnifarious
Have I read the second point right, you require that the encryption is weak? So mcrypt and so on are all out, because they only supply unacceptably strong block ciphers? Or would it be acceptable to use a strong cipher, but with an application-specific restriction that the key will not exceed a certain length, thus ensuring that it is weak when you use it, even though it isn't weak when used properly? I suppose DES has only 56 bit keys, and is in mcrypt. It's considered weak, its keys are 56 bits, which is brute-force crackable but not trivially so. - Steve Jessop

3 Answers

2
votes

What's wrong with OpenSSL? It has implementations for standard algorithms, or you can just google an implementation of DES, for example, there are many open-sources available.

2
votes

I hope there are no libraries out there which use intentionally weak ciphers (and all ciphers with short key sizes are weak by design).

But you can use any normal cryptography library and use a wrapper around this, which converts an int value to a key of the right size, by simply zero-padding it (or alternatively, by invoking a hash function with right output size).

I hope you'll inform your customers that you are not using an industry-standard strong cipher, but a weak one.

1
votes

Crypto++ is a very popular library which can do all sorts of cryptography (symmetric and asymmetric) as well as hashing and other handy features.