Global Variables
The following global variables are available globally.
-
Creates and verifies BCrypt hashes.
Use BCrypt to create hashes for sensitive information like passwords.
try BCrypt.hash("vapor", cost: 4)
BCrypt uses a random salt each time it creates a hash. To verify hashes, use the
verify(_:matches)
method.let hash = try BCrypt.hash("vapor", cost: 4) try BCrypt.verify("vapor", created: hash) // true
Declaration
Swift
public var BCrypt: BCryptDigest { get }
-
AES-256 GCM Cipher. This is the reccomended cipher mode. (see https://github.com/vapor/crypto/issues/59).
let key: Data // 32 bytes let iv: Data // 12 RANDOM bytes; different for each plaintext to encrypt. MUST be passed alongside the ciphertext to the receiver. let (ciphertext, tag) = try AES256GCM.encrypt("vapor", key: key, iv: iv) print(ciphertext) // Encrypted Data AES256GCM.decrypt(ciphertext, key: key, iv: iv, tag: tag).convert(to: String.self) // "vapor"
Declaration
Swift
public var AES256GCM: AuthenticatedCipher { get }
-
AES-128 ECB Cipher. Deprecated (see https://github.com/vapor/crypto/issues/59).
let key: Data // 16 bytes let ciphertext = try AES128.encrypt("vapor", key: key) print(ciphertext) // Encrypted Data AES128.decrypt(ciphertext, key: key).convert(to: String.self) // "vapor"
Declaration
Swift
@available(*, deprecated, message: "Stream encryption in ECB mode is unsafe (see https://github.com/vapor/crypto/issues/59﹚. Use AES256 in GCM mode instead.") public var AES128: Cipher { get }
-
AES-256 ECB Cipher. Deprecated (see https://github.com/vapor/crypto/issues/59).
let key: Data // 32 bytes let ciphertext = try AES256.encrypt("vapor", key: key) print(ciphertext) // Encrypted Data AES256.decrypt(ciphertext, key: key).convert(to: String.self) // "vapor"
Declaration
Swift
@available(*, deprecated, message: "Stream encryption in ECB mode is unsafe (see https://github.com/vapor/crypto/issues/59﹚. Use AES256 in GCM mode instead.") public var AES256: Cipher { get }
-
AES-256 CBC Cipher. Only use this if you know what you are doing; use AES-256 GCM otherwise (see https://github.com/vapor/crypto/issues/59).
let key: Data // 32 bytes let iv: Data // 16 RANDOM bytes; different for each plaintext to encrypt. MUST be passed alongside the ciphertext to the receiver. let ciphertext = try AES256.encrypt("vapor", key: key, iv: iv) print(ciphertext) // Encrypted Data AES256.decrypt(ciphertext, key: key, iv: iv).convert(to: String.self) // "vapor"
Declaration
Swift
public var AES256CBC: Cipher { get }
-
MD4 digest.
Declaration
Swift
public var MD4: Digest { get }
-
MD5 digest.
Declaration
Swift
public var MD5: Digest { get }
-
SHA-1 digest.
Declaration
Swift
public var SHA1: Digest { get }
-
SHA-224 (SHA-2) digest.
Declaration
Swift
public var SHA224: Digest { get }
-
SHA-256 (SHA-2) digest.
Declaration
Swift
public var SHA256: Digest { get }
-
SHA-384 (SHA-2) digest.
Declaration
Swift
public var SHA384: Digest { get }
-
SHA-512 (SHA-2) digest.
Declaration
Swift
public var SHA512: Digest { get }