Skip to content

Instantly share code, notes, and snippets.

@Papierkorb
Created August 26, 2017 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Papierkorb/8a0dfcff272b77c75de52f218c49a765 to your computer and use it in GitHub Desktop.
Save Papierkorb/8a0dfcff272b77c75de52f218c49a765 to your computer and use it in GitHub Desktop.
require "openssl/lib_crypto"
lib LibCrypto
fun sha256 = SHA256(data : Char*, length : SizeT, md : Char*) : Char*
end
class OpenSSL::SHA256
def self.hash(data : Bytes)
hash(data.to_unsafe, LibC::SizeT.new(data.bytesize))
end
def self.hash(data : UInt8*, bytesize : LibC::SizeT)
buffer = uninitialized UInt8[32]
LibCrypto.sha256(data, bytesize, buffer)
buffer
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment