feisty meow concerns codebase 2.140
blowfish_crypto.h
Go to the documentation of this file.
1#ifndef BLOWFISH_CRYPTO_CLASS
2#define BLOWFISH_CRYPTO_CLASS
3
4/*****************************************************************************\
5* *
6* Name : blowfish encryption *
7* Author : Chris Koeritz *
8* *
9*******************************************************************************
10* Copyright (c) 2005-$now By Author. This program is free software; you can *
11* redistribute it and/or modify it under the terms of the GNU General Public *
12* License as published by the Free Software Foundation; either version 2 of *
13* the License or (at your option) any later version. This is online at: *
14* http://www.fsf.org/copyleft/gpl.html *
15* Please send any updates to: fred@gruntose.com *
16\*****************************************************************************/
17
18#include <basis/byte_array.h>
19#include <basis/contracts.h>
20
21namespace crypto {
22
24
25class blowfish_crypto : public virtual basis::root_object
26{
27public:
30
40
41 blowfish_crypto(const blowfish_crypto &to_copy);
42
43 virtual ~blowfish_crypto();
44
46
47 DEFINE_CLASS_NAME("blowfish_crypto");
48
49 int key_size() const; // returns the size of our key, in bits.
50
51 static int minimum_key_size();
53 static int maximum_key_size();
55
56 const basis::byte_array &get_key() const;
57
58 bool set_key(const basis::byte_array &new_key, int key_size);
60
61 static void generate_key(int size, basis::byte_array &new_key);
63
64 bool encrypt(const basis::byte_array &source, basis::byte_array &target) const;
66
67 bool decrypt(const basis::byte_array &source, basis::byte_array &target) const;
69
70 // seldom-needed methods...
71
72 static const basis::byte_array &init_vector();
74
82private:
83 int _key_size;
84 basis::byte_array *_key;
85};
86
87} //namespace.
88
89#endif
90
A very common template for a dynamic array of bytes.
Definition byte_array.h:36
Provides BlowFish encryption on byte_arrays using the OpenSSL package.
static int minimum_key_size()
returns the minimum key size (in bits) supported here.
bool decrypt(const basis::byte_array &source, basis::byte_array &target) const
decrypts the "target" array from the encrypted "source" array.
DEFINE_CLASS_NAME("blowfish_crypto")
static const basis::byte_array & init_vector()
returns the initialization vector that is used by this class.
bool encrypt(const basis::byte_array &source, basis::byte_array &target) const
encrypts the "source" array into the "target" array.
static int maximum_key_size()
returns the maximum key size (in bits) supported here.
blowfish_crypto & operator=(const blowfish_crypto &to_copy)
static void generate_key(int size, basis::byte_array &new_key)
creates a "new_key" of the "size" (in bits) specified.
bool set_key(const basis::byte_array &new_key, int key_size)
sets the encryption key to "new_key".
const basis::byte_array & get_key() const
returns our current key.