Skip to content

Instantly share code, notes, and snippets.

Christopher Prince crspybits

View GitHub Profile
@crspybits
crspybits / ContentHash.swift
Created Oct 22, 2018
Create Dropbox Content Hash in Swift on iOS
View ContentHash.swift
// CommonCrypto is only available with Xcode 10 for import into Swift; see also https://stackoverflow.com/questions/25248598/importing-commoncrypto-in-a-swift-framework
import CommonCrypto
class Hashing {
// From https://stackoverflow.com/questions/25388747/sha256-in-swift
private static func sha256(data : Data) -> Data {
var hash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH))
data.withUnsafeBytes {
_ = CC_SHA256($0, CC_LONG(data.count), &hash)
}
@crspybits
crspybits / gist:e43c68cffe74de27f0a157006c1220e6
Created Oct 22, 2018
Create Dropbox Content Hash in Swift
View gist:e43c68cffe74de27f0a157006c1220e6
// CommonCrypto is only available with Xcode 10 for import into Swift; see also https://stackoverflow.com/questions/25248598/importing-commoncrypto-in-a-swift-framework
import CommonCrypto
class Hashing {
// From https://stackoverflow.com/questions/25388747/sha256-in-swift
private static func sha256(data : Data) -> Data {
var hash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH))
data.withUnsafeBytes {
_ = CC_SHA256($0, CC_LONG(data.count), &hash)
}
View gist:6973616226e2a6ffec6653257fc69a01
// CommonCrypto is only available with Xcode 10 for import into Swift; see also https://stackoverflow.com/questions/25248598/importing-commoncrypto-in-a-swift-framework
import CommonCrypto
class Hashing {
// From https://stackoverflow.com/questions/25388747/sha256-in-swift
private static func sha256(data : Data) -> Data {
var hash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH))
data.withUnsafeBytes {
_ = CC_SHA256($0, CC_LONG(data.count), &hash)
}
@crspybits
crspybits / gist:d8d34d18a08eab57c62a0b30f64c4f64
Created May 30, 2018
Cloudinary signature generation, in Swift-- using the CryptoSwift Cocoapod for SHA1 hash.
View gist:d8d34d18a08eab57c62a0b30f64c4f64
/* 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]()
You can’t perform that action at this time.