- Inherits from:
- Object
- Declared in:
- DSHA256.h
Object
|
+---DSHA256
Class Description
The DSHA256 class implements a number of methods for using the NIST's SHA256
algorithm.
- Example:
#include <stdio.h>
#include "ofc/DSHA256.h"
int main(int argc, char *argv[])
{
DSHA256 *sha1 = [DSHA256 alloc];
DSHA256 *sha2 = [DSHA256 new ];
DText *str;
DData *data;
[sha1 init :"This is a test string for SHA256"]; // Init with a test string
str = [sha1 hexdigest]; // Convert sha256 value to hexstring
printf("SHA256 of \"This is a test string for SHA256\" in hex-string is:%s.\n", [str cstring]);
[str free];
[sha2 update :"abcdefghijklmnopqrstuvwxyz"]; // Feed the sha2 variable with a c-string
[sha2 update :"0123456789" :10]; // Feed the sha2 variable with data string
data = [sha2 digest];
str = [data toBase64]; // Get SHA256 value and convert to base 64
printf("SHA256 of test string in base64 is:%s.\n", [str cstring]);
[str free];
[data free];
[sha1 free]; // Cleanup
[sha2 free];
return 0;
}
- Last modified:
- 02-Aug-2008 (DSHA256.h)
Instance Variables
- private uint32_t _h[8]
- private uint32_t _count[2]
- private unsigned char _input[64]
- Constructors
- - (DSHA256 *) init
- Initialise the sha256 object
- Returns:
- the object
- - (DSHA256 *) init :(const char *) cstring
- Initialise the sha256 object with a string
- Parameters:
- cstring - the c-string
- Returns:
- the object
- - (DSHA256 *) init :(const unsigned char *) data :(unsigned long) length
- Initialise the sha256 object with data
- Parameters:
- data - the data ('\0' allowed)
length - the length of the data
- Returns:
- the object
- Reset method
- - (DSHA256 *) reset
- Reset the sha256 object
- Returns:
- the object
- Update methods
- - (DSHA256 *) update :(const char *) cstring
- Update the object with a c-string. Repeated calls can be compared
to a single call in which the strings are concatenated
- Parameters:
- cstring - the c-string to be feeded to sha256
- Returns:
- the object
- - (DSHA256 *) update :(const unsigned char *) data :(unsigned long) length
- Update the sha256 object with data. Repeated calls can be compared
to a single call in which the strings are concatenated
- Parameters:
- data - the data to be feeded to sha256
length - the length of the data
- Returns:
- the object
- Digest methods
- - (DData *) digest
- Return the (current) digest of all data passed to the object.
- Returns:
- the (new) data string object with the digest
- - (DText *) hexdigest
- Returns the (current) digest of all data passed to the object. The
returning string contains the digest in hexadecimal ascii characters.
- Returns:
- the (new) string object with the digest
generated 06-Sep-2008 by ObjcDoc 3.0.0