Пример #1
0
/**
 *  @brief 	This method ends the hash process
 *  		and returns the hash as string.
 *
 *  @return 	a hash as std::string
 */  
std::string sha1wrapper::hashIt(void)
{
	hl_uint8 Message_Digest[20];
	sha1->SHA1Result(&context, Message_Digest);

	return convToString(Message_Digest);
}
/**
 *  @brief 	This method ends the hash process
 *  		and returns the hash as string.
 *
 *  @return 	a hash as std::string
 */  
std::string sha256wrapper::hashIt(void)
{
	sha2_byte buff[SHA256_DIGEST_STRING_LENGTH];
	sha256->SHA256_End(&context,(char*)buff);

	return convToString(buff);
}
Пример #3
0
// Creates a MD5 hash from a file specified in "filename" and returns it as string 
// (based on Ronald L. Rivest's code from RFC1321 "The MD5 Message-Digest Algorithm") 
string getHashFromFile(const string &filename)	
{
   const S32 ChunkSize = 1024;

	unsigned int len;
  	unsigned char buffer[ChunkSize], digest[16];

	// Open file
   FILE *file = fopen (filename.c_str(), "rb");
   if(!file)
		return "-1";

	// Init md5
   hash_state md;
   md5_init(&md);

	// Read the file
	while( (len = (unsigned int)fread (buffer, 1, ChunkSize, file)) )
	   md5_process(&md, buffer, len);

	// Generate hash, close the file, and return the hash as string
   md5_done(&md, digest);
 	fclose (file);

	return convToString(digest);
}
/*
 * creates a MD5 hash from
 * a file specified in "filename" and 
 * returns it as string
 * (based on Ronald L. Rivest's code
 * from RFC1321 "The MD5 Message-Digest Algorithm")
 */	
std::string MD5Wrapper::getHashFromFile(std::string filename) {
	FILE *file;
  	MD5_CTX context;
  
	int len;
  	unsigned char buffer[1024], digest[16];

	//open file
  	if ((file = fopen (filename.c_str(), "rb")) == NULL)
	{
		return "-1";
	}

	//init md5
 	md5->MD5Init (&context);
 	
	//read the filecontent
	while ( (len = fread (buffer, 1, 1024, file)) )
   	{
		md5->MD5Update (&context, buffer, len);
	}
	
	/*
	generate hash, close the file and return the
	hash as std::string
	*/
	md5->MD5Final (digest, &context);
 	fclose (file);
	return convToString(digest);
 }	
Пример #5
0
/**
 *  @brief 	This method ends the hash process
 *  		and returns the hash as string.
 *
 *  @return 	the hash as std::string
 */
std::string md5wrapper::hashIt(void)
{
    //create the hash
    unsigned char buff[16] = "";
    md5->MD5Final((unsigned char*)buff,&ctx);

    //converte the hash to a string and return it
    return convToString(buff);
}
Пример #6
0
/*
 * creates a MD5 hash from
 * a file specified in "filename" and
 * returns it as string
 * (based on Ronald L. Rivest's code
 * from RFC1321 "The MD5 Message-Digest Algorithm")
 */
std::string md5wrapper::getHashFromFile(std::string filename, uint32_t & length, char * first_kb)
{
    FILE *file;
    MD5Context context;

    int len;
    int saved = 0;
    unsigned char buffer[1024], digest[16];

    //open file
    if ((file = fopen (filename.c_str(), "rb")) == NULL)
    {
        return "file unreadable.";
    }
    length = 0;
    //init md5
    MD5Init (&context);

    //read the filecontent
    while (1)
    {
        errno = 0;
        len = fread (buffer, 1, 1024, file);
        if(saved < 1024 && first_kb)
        {
            memcpy(first_kb + saved, buffer, std::min (len, 1024 - saved));
            saved += len;
        }
        length += len;
        if(len != 1024)
        {
            int err = ferror(file);
            //FIXME: check errno here.
            if(err)
            {
                fclose(file);
                return strerror(err);
            }
            if(feof(file))
            {
                MD5Update (&context, buffer, len);
                break;
            }
        }
        MD5Update (&context, buffer, len);
    }

    /*
    generate hash, close the file and return the
    hash as std::string
    */
    MD5Final (digest, &context);
    fclose (file);
    return convToString(digest);
 }
Пример #7
0
// Internal hash function, calling the basic methods from md5.h
static string hash(const string &text)
{
   unsigned char outBuffer[16] = "";
   hash_state md;

   md5_init(&md);
   md5_process(&md, (unsigned char*)text.c_str(), (unsigned int)text.length());
   md5_done(&md, outBuffer);

	// Convert the hash to a string and return it
	return convToString(outBuffer);
}
Пример #8
0
/*
 * internal hash function, calling
 * the basic methods from md5.h
 */
std::string md5wrapper::hashit(unsigned char *data, size_t length)
{
	MD5Context ctx;

	//init md5
	MD5Init(&ctx);
	//update with our string
	MD5Update(&ctx, data, length);

	//create the hash
	unsigned char buff[16] = "";
	MD5Final((unsigned char*)buff,&ctx);

	//converte the hash to a string and return it
	return convToString(buff);
}
/*
 * internal hash function, calling
 * the basic methods from md5.h
 */	
std::string MD5Wrapper::hashit(std::string text) {
	MD5_CTX ctx;
	
	//init md5
	md5->MD5Init(&ctx);
	//update with our string
	md5->MD5Update(&ctx,
		 (unsigned char*)text.c_str(),
		 text.length());
	
	//create the hash
	unsigned char buff[16] = "";	
	md5->MD5Final((unsigned char*)buff,&ctx);

	//converte the hash to a string and return it
	return convToString(buff);	
}
Пример #10
0
// Return the final computed hash
string IncrementalHasher::getHash()
{
   U8 digest[16];
   md5_done(&mHashState, digest);
	return convToString(digest);
}