Skip to content

Instantly share code, notes, and snippets.

View crspybits's full-sized avatar
🏠
Working from home

Christopher Prince crspybits

🏠
Working from home
View GitHub Profile
@crspybits
crspybits / gist:d8d34d18a08eab57c62a0b30f64c4f64
Created May 30, 2018 18:21
Cloudinary signature generation, in Swift-- using the CryptoSwift Cocoapod for SHA1 hash.
/* Experimenting with creating a signature to make it easier to do the server-side development.
See https://github.com/cloudinary/cloudinary_java/blob/master/cloudinary-core/src/main/java/com/cloudinary/Cloudinary.java#L129
and https://support.cloudinary.com/hc/en-us/articles/203817991-How-to-generate-a-Cloudinary-signature-on-my-own-
*/
// The optional timestamp is for testing this method-- this should be a UNIX timestamp with no trailing decimals-- i.e., just an integer number.
// Don't use "public_id" or "timestamp" as keys in otherParams if you give it.
func createSignature(publicId: String, apiSecret: String, otherParams: [String: Any]? = nil, timestamp: String? = nil) -> (signature: String, timestamp: String)? {
// 1) Set up the parameters we're going to use in the signing.
var params = [String: Any]()