Type Method
encode(_:)
Encodes raw bytes using the URL-safe unpadded Base64 alphabet.
static func encode(_ data: Data) -> String
Parameters
-
data
-
The bytes to encode. May be empty; the empty input produces the empty string.
Return Value
A Base64URL string consisting solely of characters from the 64-symbol URL-safe alphabet plus no padding. Round- tripped via decode(_:) to recover the original bytes.
Mentioned In
Discussion
Emits the encoding defined in RFC 4648 §5: the standard Base64 alphabet with + replaced by -, / replaced by _, and the trailing = padding stripped. The output is safe to drop into URL path segments, query parameter values, HTTP header fields, JSON string values, JWS/JWT segments, and filename components without further escaping.
Implementation detail: this is a thin layer over Foundation’s Data.base64EncodedString() followed by alphabet translation and padding removal. It does not call into libcrypto.
Note
Not constant-time with respect to the input length or content. Do not use on side-channel-sensitive material.