SHA (Secure Hash Algorithm,译作安全散列算法) 是美国国家安全局 (NSA) 设计,美国国家标准与技术研究院 (NIST) 发布的一系列密码散列函数。
特点是一次一密,无法破解
下面直接上MATLAB代码
首先是生成Hash函数的m文件
inp -> 你的密钥
meth -> 加密方案,可选MD2, MD5, SHA-1, SHA-256, SHA-384, SHA-512
function h = hash(inp,meth)
% HASH - Convert an input variable into a message digest using any of
% several common hash algorithms
%
% USAGE: h = hash(inp,'meth')
%
% inp = input variable, of any of the following classes:
% char, uint8, logical, double, single, int8, uint8,
% int16, uint16, int32, uint32, int64, uint64
% h = hash digest output, in hexadecimal notation
% meth = hash algorithm, which is one of the following:
% MD2, MD5, SHA-1, SHA-256, SHA-384, or SHA-512
%
% NOTES: (1) If the input is a string or uint8 variable, it is hashed
% as usual for a byte stream. Other classes are converted into
% their byte-stream values. In other words, the hash of the
% following will be identical: