nsICryptoHMAC 编辑

netwerk/base/public/nsICryptoHMAC.idlScriptable This interface provides HMAC signature algorithms. 1.0 66 Introduced Gecko 1.9 Inherits from: nsISupports Last changed in Gecko 1.9 (Firefox 3)

Method overview

ACString finish(in PRBool aASCII);
void init(in unsigned long aAlgorithm, in nsIKeyObject aKeyObject);
void reset();
void update([const, array, size_is(aLen)] in octet aData, in unsigned long aLen);
void updateFromStream(in nsIInputStream aStream, in unsigned long aLen);

Constants

Hashing Algorithms. These values are to be used by the init() method to indicate which hashing function to use. These values map onto the values defined in mozilla/security/nss/lib/softoken/pkcs11t.h and are switched to CKM_*_HMAC constant.

ConstantValueDescription
MD21Message Digest Algorithm 2
MD52Message-Digest algorithm 5
SHA13Secure Hash Algorithm 1
SHA2564Secure Hash Algorithm 256
SHA3845Secure Hash Algorithm 384
SHA5126Secure Hash Algorithm 512

Methods

finish()

Completes this HMAC object and produces the actual HMAC diegest data.

Note: This method may be called any time after init() is called. This call resets the object to its pre-init state.
ACString finish(
  in PRBool aASCII
);
Parameters
aASCII
If true then the returned value is a base-64 encoded string. if false, then the returned value is binary data.
Return value

A hash of the data that was read by this object. This can be either binary data or base 64 encoded.

Exceptions thrown
NS_ERROR_NOT_INITIALIZED
If init() has not been called.

init()

Initialize the hashing object. This method may be called multiple times with different algorithm types.

Warning: This approach is not FIPS compliant. Note: This method must be called before any other method on this interface is called.
void init(
  in unsigned long aAlgorithm,
  in nsIKeyObject aKeyObject
);
Parameters
aAlgorithm
The algorithm type to be used. This value must be one of the above valid algorithm types.
aKeyObject
Object holding a key. To create the key object use for instance:
var keyObject = Components.classes["@mozilla.org/security/keyobjectfactory;1"]
                .getService(Components.interfaces.nsIKeyObjectFactory)
                .keyFromString(Components.interfaces.nsIKeyObject.HMAC, rawKeyData);
Exceptions thrown
NS_ERROR_INVALID_ARG
If an unsupported algorithm type is passed.

reset()

Reinitialize HMAC context to be reused with the same settings (the key and hash algorithm) but on different set of data.

void reset();
Parameters

None.

update()

void update(
  [const, array, size_is(aLen)] in octet aData,
  in unsigned long aLen
);
Parameters
aData
A buffer to calculate the hash over.
aLen
The length of the buffer aData.
Exceptions thrown
NS_ERROR_NOT_INITIALIZED
If init() has not been called.

updateFromStream()

Calculates and updates a new hash based on a given data stream.

void updateFromStream(
  in nsIInputStream aStream,
  in unsigned long aLen
);
Parameters
aStream
An input stream to read from.
aLen
How much to read from the given aStream. Passing PR_UINT32_MAX indicates that all data available will be used to update the hash.
Exceptions thrown
NS_ERROR_NOT_INITIALIZED
If init() has not been called.
NS_ERROR_NOT_AVAILABLE
If the requested amount of data to be calculated into the hash is not available.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:33 次

字数:7163

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文