|
@@ -35,54 +35,6 @@ char *encrypt_string(const char *keydata, char *in)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-/**
|
|
|
|
|
- * @brief Encrypt a string with AES 256 ECB
|
|
|
|
|
- * @param key The key to encrypt with
|
|
|
|
|
- * @param data The string to encrypt
|
|
|
|
|
- * @return A new, encrypted string
|
|
|
|
|
- */
|
|
|
|
|
-bd::String encrypt_string(const bd::String& key, const bd::String& data) {
|
|
|
|
|
- if (!key) return data;
|
|
|
|
|
- size_t len = data.length();
|
|
|
|
|
- char *bdata = (char*) aes_encrypt_ecb_binary(key.c_str(), (unsigned char*) data.c_str(), &len);
|
|
|
|
|
- bd::String encrypted(bdata, len);
|
|
|
|
|
- free(bdata);
|
|
|
|
|
- return encrypted;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-#ifdef not_needed
|
|
|
|
|
-/**
|
|
|
|
|
- * @brief Encrypt a string with Blowfish ECB
|
|
|
|
|
- * @param key The key to encrypt with
|
|
|
|
|
- * @param data The string to encrypt
|
|
|
|
|
- * @return A new, encrypted string
|
|
|
|
|
- */
|
|
|
|
|
-bd::String encrypt_string_bf(const bd::String& key, const bd::String& data) {
|
|
|
|
|
- if (!key) return data;
|
|
|
|
|
- size_t len = data.length();
|
|
|
|
|
- char *bdata = (char*) bf_encrypt_ecb_binary(key.c_str(), (unsigned char*) data.c_str(), &len);
|
|
|
|
|
- bd::String encrypted(bdata, len);
|
|
|
|
|
- free(bdata);
|
|
|
|
|
- return encrypted;
|
|
|
|
|
-}
|
|
|
|
|
-#endif
|
|
|
|
|
-
|
|
|
|
|
-/**
|
|
|
|
|
- * @brief Encrypt a string with AES 256 CBC
|
|
|
|
|
- * @param key The key to encrypt with
|
|
|
|
|
- * @param data The string to encrypt
|
|
|
|
|
- * @param IV The IV to use (WARNING: This is modified inplace)
|
|
|
|
|
- * @return A new, encrypted string
|
|
|
|
|
- */
|
|
|
|
|
-bd::String encrypt_string_cbc(const bd::String& key, const bd::String& data, unsigned char* IV) {
|
|
|
|
|
- if (!key) return data;
|
|
|
|
|
- size_t len = data.length();
|
|
|
|
|
- char *bdata = (char*) aes_encrypt_cbc_binary(key.c_str(), (unsigned char*) data.c_str(), &len, IV);
|
|
|
|
|
- bd::String encrypted(bdata, len);
|
|
|
|
|
- free(bdata);
|
|
|
|
|
- return encrypted;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
char *decrypt_string(const char *keydata, char *in)
|
|
char *decrypt_string(const char *keydata, char *in)
|
|
|
{
|
|
{
|
|
|
size_t len = strlen(in);
|
|
size_t len = strlen(in);
|
|
@@ -101,39 +53,6 @@ char *decrypt_string(const char *keydata, char *in)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-/**
|
|
|
|
|
- * @brief Decrypt an AES 256 ECB ciphered string
|
|
|
|
|
- * @param key The key to decrypt with
|
|
|
|
|
- * @param data The string to decrypt
|
|
|
|
|
- * @return A new, decrypted string
|
|
|
|
|
- */
|
|
|
|
|
-bd::String decrypt_string(const bd::String& key, const bd::String& data) {
|
|
|
|
|
- if (!key) return data;
|
|
|
|
|
- size_t len = data.length();
|
|
|
|
|
- char *bdata = (char*) aes_decrypt_ecb_binary(key.c_str(), (unsigned char*) data.c_str(), &len);
|
|
|
|
|
- bd::String decrypted(bdata, len);
|
|
|
|
|
- OPENSSL_cleanse(bdata, len);
|
|
|
|
|
- free(bdata);
|
|
|
|
|
- return decrypted;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-/**
|
|
|
|
|
- * @brief Decrypt anAES 256 CBC ciphered string
|
|
|
|
|
- * @param key The key to decrypt with
|
|
|
|
|
- * @param data The string to decrypt
|
|
|
|
|
- * @param IV The IV to use (WARNING: This is modified inplace)
|
|
|
|
|
- * @return A new, decrypted string
|
|
|
|
|
- */
|
|
|
|
|
-bd::String decrypt_string_cbc(const bd::String& key, const bd::String& data, unsigned char* IV) {
|
|
|
|
|
- if (!key) return data;
|
|
|
|
|
- size_t len = data.length();
|
|
|
|
|
- char *bdata = (char*) aes_decrypt_cbc_binary(key.c_str(), (unsigned char*) data.c_str(), &len, IV);
|
|
|
|
|
- bd::String decrypted(bdata, len);
|
|
|
|
|
- OPENSSL_cleanse(bdata, len);
|
|
|
|
|
- free(bdata);
|
|
|
|
|
- return decrypted;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
int salted_sha1cmp(const char *salted_hash, const char *string) {
|
|
int salted_sha1cmp(const char *salted_hash, const char *string) {
|
|
|
char* cmp = salted_sha1(string, &salted_hash[1]); //Pass in the salt from the given hash
|
|
char* cmp = salted_sha1(string, &salted_hash[1]); //Pass in the salt from the given hash
|
|
|
int n = strcmp(salted_hash, cmp);
|
|
int n = strcmp(salted_hash, cmp);
|