美文网首页Vapor
Vapor系列教程 - Hash

Vapor系列教程 - Hash

作者: CaryZheng | 来源:发表于2016-09-07 10:37 被阅读137次

Vapor 内置支持 Hash 。

示例


想要获取一个字符串的 Hash 值,只需使用 Droplet 中的 hash 即可。

let hashed = drop.hash.make("vapor")

print("\(hashed)")

输出

ac774af08cfe40f22367bad426cacb321da40fa28daeefb745e251defd365d20

SHA2Hasher


默认情况下, Vapor 使用 256 位的 SHA2Hasher ,不过也可以通过如下方式更改。

let sha512 = SHA2Hasher(variant: .sha512)
let drop = Droplet(hash: sha512)

自定义 Hash


Vapor 也支持自定义 Hash ,只需要遵循 Hash 协议即可。

public protocol Hash: class {
    /**
        A string used to add an additional 
        layer of security to all hashes
    */
    var key: String { get set }

    /**
        Given a string, this function will
        return the hashed string according
        to whatever algorithm it chooses to implement.
    */
    func make(_ string: String) -> String
}

Go to Vapor系列教程 - 目录

相关文章

  • Vapor系列教程 - Hash

    Vapor 内置支持 Hash 。 示例 想要获取一个字符串的 Hash 值,只需使用 Droplet 中的 ha...

  • Vapor学习

    通过将Vapor官方文档进行梳理,了解Vapor所涉及到的知识点 Vapor英文教程Vapor中文教程官方Github

  • Vapor系列教程 - 目录

    Vapor Version: v0.16 介绍 第一章 Vapor 起航1.1 macOS 安装 Swift1.2...

  • Vapor系列教程 - 介绍

    Vapor 是基于 Swift 实现的 Web 框架与服务,可运行于 macOS 和 Ubuntu 系统上。 特性...

  • Vapor系列教程 - Views

    Vapor 可直接返回纯 HTML 页面,也可以用 Mustache 或 Stencil 模版来渲染页面。 目录 ...

  • Vapor系列教程 - Middleware

    Middleware 是现代 Web 框架中必不可少的一部分。通过 Middleware 可以单独处理 Reque...

  • Vapor系列教程 - Validation

    Vapor 提供了一种机制来验证数据的合法性。 基本用法 验证 Employee 的 email 和 name 数...

  • Vapor系列教程 - Provider

    Provider 使得给 Vapor 添加功能和第三方 Package 变得更容易,只要遵循 Provider 协...

  • Vapor系列教程 - Droplet

    Droplet 是一个比较综合的类,它负责路由的注册、服务的启动和中间件的添加等等。 初始化 编辑 main.sw...

  • Vapor系列教程 - Config

    Vapor 有一套灵活的配置系统,可根据不同的应用环境来定制相应的配置。 配置 所有配置文件均存放于 Config...

网友评论

    本文标题:Vapor系列教程 - Hash

    本文链接:https://www.haomeiwen.com/subject/modjettx.html