📄 sha.cpp
字号:
/** * @file sha.cpp * @brief 字符串的包装,sha1单向散列函数 * @author 泥偶 * @since 2003-09-26 * @date 2003-11-03 */#define HAVE_MEMCPY#include "xstring.hpp"namespace x{ namespace { #include <string.h> #include "sha.c" } // namespace//---------------------------------------------------------------------------- /** 根据 <a href="http://www.faqs.org/rfcs/rfc3174">US Secure Hash Algorithm 1</a> 计算字符串的sha1散列。这个散列是一个40个字符的十六进制数字。 如果可选的raw_output被设置成true,那将会返回20个字符长度的原始二进制格式。 @code * xstring str = "apple"; * if ("d0be2dc421be4fcd0172e5afceea3970e2f3d940" == str.sha1()) * { * cout << "Would you like a green or red apple?"; * } @endcode raw_output参数是1.0.2test3版本新增的 @see crc32() md5() */ xstring xstring::sha1(bool raw_output) const { char digest[20]; sha_buffer(this->data(), this->size(), digest); xstring str(digest, sizeof(digest)); if (raw_output) { return str; } return str.bin2hex(); }} // namespace x
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -