/** * Copyright (c) 2014 Baidu.com, Inc. All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file src/crypto.ts * @author leeight */ import { Readable } from 'stream'; /** 支持的字符编码类型 */ export type BufferEncoding = 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex'; /** 支持的摘要输出格式 */ export type DigestEncoding = 'base64' | 'base64url' | 'hex' | 'binary'; /** * 计算数据的 MD5 哈希值 * @param data 要计算哈希的数据 * @param enc 输入数据的编码方式 * @param digest 输出摘要的格式 * @returns MD5 哈希值 */ export declare function md5sum(data: string | Buffer, enc?: BufferEncoding, digest?: DigestEncoding): string; /** * 计算流的 MD5 哈希值 * @param stream 可读流 * @param digest 输出摘要的格式 * @returns Promise,解析为 MD5 哈希值 */ export declare function md5stream(stream: Readable, digest?: DigestEncoding): Promise; /** * 计算文件的 MD5 哈希值 * @param filename 文件路径 * @param digest 输出摘要的格式 * @returns Promise,解析为 MD5 哈希值 */ export declare function md5file(filename: string, digest?: DigestEncoding): Promise; /** * 计算 Blob 对象的 MD5 哈希值(仅在浏览器环境中可用) * @param blob Blob 对象 * @param digest 输出摘要的格式 * @returns Promise,解析为 MD5 哈希值 */ export declare function md5blob(blob: Blob, digest?: DigestEncoding): Promise; /** * 创建 HMAC 签名 * @param algorithm 哈希算法 * @param key 密钥 * @param data 要签名的数据 * @param encoding 输出编码 * @returns HMAC 签名 */ export declare function hmac(algorithm: string, key: string | Buffer, data: string | Buffer, encoding?: DigestEncoding): string; /** * 创建 SHA256 哈希 * @param data 要哈希的数据 * @param encoding 输出编码 * @returns SHA256 哈希值 */ export declare function sha256(data: string | Buffer, encoding?: DigestEncoding): string; /** * 生成随机字符串 * @param length 字符串长度 * @param encoding 输出编码 * @returns 随机字符串 */ export declare function randomString(length?: number, encoding?: DigestEncoding): string; declare const _default: { md5sum: typeof md5sum; md5stream: typeof md5stream; md5file: typeof md5file; md5blob: typeof md5blob; hmac: typeof hmac; sha256: typeof sha256; randomString: typeof randomString; }; export default _default; //# sourceMappingURL=crypto.d.ts.map