From 98b02209a438ddd4358eda58870100287c3924d1 Mon Sep 17 00:00:00 2001 From: George Marques Date: Thu, 23 Jun 2016 13:57:45 -0300 Subject: Add sha256_buffer() function to String --- core/ustring.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'core/ustring.cpp') diff --git a/core/ustring.cpp b/core/ustring.cpp index ea9a9d903..43e3a9a0b 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -2419,6 +2419,23 @@ Vector String::md5_buffer() const { return ret; }; +Vector String::sha256_buffer() const { + CharString cs = utf8(); + unsigned char hash[32]; + sha256_context ctx; + sha256_init(&ctx); + sha256_hash(&ctx, (unsigned char*)cs.ptr(), cs.length()); + sha256_done(&ctx, hash); + + Vector ret; + ret.resize(32); + for (int i = 0; i < 32; i++) { + ret[i] = hash[i]; + } + + return ret; +} + String String::insert(int p_at_pos,String p_string) const { -- cgit v1.2.3-70-g09d2