- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

gmd5.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2013 Graeme Walker <graeme_walker@users.sourceforge.net>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
20
21 #ifndef G_MD5_H
22 #define G_MD5_H
23
24 #include "gdef.h"
25 #include "gexception.h"
26 #include <string>
27
29 namespace G
30 {
31 class Md5 ;
32 }
33
37 class G::Md5
38 {
39 public:
40 G_EXCEPTION( InvalidMaskedKey , "invalid md5 key" ) ;
41 G_EXCEPTION( Error , "internal md5 error" ) ;
43 struct Masked
44 {} ;
45
46 static std::string digest( const std::string & input ) ;
49
50 static std::string digest( const std::string & input_1 , const std::string & input_2 ) ;
52
53 static std::string printable( const std::string & input ) ;
57
58 static std::string hmac( const std::string & key , const std::string & input ) ;
62
63 static std::string hmac( const std::string & masked_key , const std::string & input , Masked ) ;
65
66 static std::string mask( const std::string & key ) ;
68
69 private:
70 static std::string digest( const std::string & input_1 , const std::string * input_2 ) ;
71 static std::string mask( const std::string & k64 , const std::string & pad ) ;
72 static std::string xor_( const std::string & , const std::string & ) ;
73 static std::string key64( std::string ) ;
74 static std::string ipad() ;
75 static std::string opad() ;
76 Md5() ;
77 } ;
78
79 #endif
G::Md5::Masked
An overload discriminator for G::Md5::hmac()
Definition: gmd5.h:43
G::Md5::hmac
static std::string hmac(const std::string &key, const std::string &input)
Computes a Hashed Message Authentication Code using MD5 as the hash function.
Definition: gmd5_native.cpp:167
G
Low-level classes.
G::Md5::mask
static std::string mask(const std::string &key)
Masks an HMAC key so that it can be stored more safely.
Definition: gmd5_native.cpp:137
G::Md5::digest
static std::string digest(const std::string &input)
Creates an MD5 digest.
Definition: gmd5_native.cpp:173
gexception.h
G_EXCEPTION
#define G_EXCEPTION(class_name, description)
define as a function rather than a type if optimising for size
Definition: gexception.h:93
G::Md5
MD5 class.
Definition: gmd5.h:37
G::Md5::printable
static std::string printable(const std::string &input)
Converts a binary string into a printable form, using a lowercase hexadecimal encoding.
Definition: gmd5_native.cpp:193