sha256

Java: Calculate SHA-256 hash of large file efficiently

。_饼干妹妹 提交于 2019-11-29 21:55:27
I need to calculate a SHA-256 hash of a large file (or portion of it). My implementation works fine, but its much slower than the C++'s CryptoPP calculation (25 Min. vs. 10 Min for ~30GB file). What I need is a similar execution time in C++ and Java, so the hashes are ready at almost the same time. I also tried the Bouncy Castle implementation, but it gave me the same result. Here is how I calculate the hash: int buff = 16384; try { RandomAccessFile file = new RandomAccessFile("T:\\someLargeFile.m2v", "r"); long startTime = System.nanoTime(); MessageDigest hashSum = MessageDigest.getInstance(

MD5 SHA1 SHA256的校验

你。 提交于 2019-11-29 21:36:27
Windows下使用自带certutil工具校验文件MD5、SHA1、SHA256。 Windows下shell(或cmd)中也集成了专门的工具用来校验文件的MD5值、SHA1值、SHA256值的,吼吼吼!命令是: certutil -hashfile xxx MD5 certutil -hashfile xxx SHA1 certutil -hashfile xxx SHA256 xxx表示将验证文件的绝对路径(地址要填对); 来源: https://my.oschina.net/u/4075942/blog/3107091

How to encrypt data using RSA, with SHA-256 as hash function and MGF1 as mask generating function?

[亡魂溺海] 提交于 2019-11-29 14:23:08
问题 I was doing some experiments with cryptography. Now I have the public key of receiver and i want to encrypt some data and pass to the receiver. I want to use RSAES-OAEP algorithm. with SHA-256 as hash function and MGF1 as mask generation function. I want do this using openssl. I found a function RSA_public_encrypt() with this function we can specify the padding. One of the padding option available was RSA_PKCS1_OAEP_PADDING EME-OAEP as defined in PKCS #1 v2.0 with SHA-1 , MGF1 . they are

Why isn't my PHP SHA256 hash equivalent to C# SHA256Managed hash

谁都会走 提交于 2019-11-29 13:14:00
Why aren't these the same? php: $hash = hash('sha256', $userData['salt'] . hash('sha256', $password) ); c# public static string ComputeHash(string plainText, string salt) { // Convert plain text into a byte array. byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText); byte[] saltBytes = Encoding.UTF8.GetBytes(salt); SHA256Managed hash = new SHA256Managed(); // Compute hash value of salt. byte[] plainHash = hash.ComputeHash(plainTextBytes); byte[] concat = new byte[plainHash.Length + saltBytes.Length]; System.Buffer.BlockCopy(saltBytes, 0, concat, 0, saltBytes.Length); System.Buffer

Excel formula-based function for SHA256 / SHA512 hashing without VBA or macros

与世无争的帅哥 提交于 2019-11-29 10:47:58
It's the year 2017 and anybody who needs to use hashes should avoid 'broken' ones such as MD5, if security is important. Has anybody found or created a way to do more secure SHA256 or SHA512 hashing in Excel, without using VBA or macros? A spectacular example of this being done before was over 3½ years ago with MD5 (as seen in this SO: MD5 Hash function in excel without using VBA ). Reason for avoiding VBA/Macros: Compatibility with mobile devices, such as Excel for iOS. Side Note: The original Stack Overflow post has a successful answer with a dead link, here is a new link for reference:

Calculate and print SHA256 hash of a file using OpenSSL

℡╲_俬逩灬. 提交于 2019-11-29 09:56:04
I'm trying to write a C function using OpenSSL/libcrypto to calculate the SHA256 sum of a file. I'm basing my code on Adam Lamer's c++ example here . Here's my code: int main (int argc, char** argv) { char calc_hash[65]; calc_sha256("file.txt", calc_hash); } int calc_sha256 (char* path, char output[65]) { FILE* file = fopen(path, "rb"); if(!file) return -1; char hash[SHA256_DIGEST_LENGTH]; SHA256_CTX sha256; SHA256_Init(&sha256); const int bufSize = 32768; char* buffer = malloc(bufSize); int bytesRead = 0; if(!buffer) return -1; while((bytesRead = fread(buffer, 1, bufSize, file))) { SHA256

Is it okay to truncate a SHA256 hash to 128 bits?

故事扮演 提交于 2019-11-29 09:21:23
MD5 and SHA-1 hashes have weaknesses against collision attacks. SHA256 does not but it outputs 256 bits. Can I safely take the first or last 128 bits and use that as the hash? I know it will be weaker (because it has less bits) but otherwise will it work? Basically I want to use this to uniquely identify files in a file system that might one day contain a trillion files. I'm aware of the birthday problem and a 128 bit hash should yield about a 1 in a trillion chance on a trillion files that there would be two different files with the same hash. I can live with those odds. What I can't live

不同版本的jquery

会有一股神秘感。 提交于 2019-11-29 08:22:24
http://code.jquery.com/ 到此地址查看; jQuery 3.x jQuery Core 3.4.1 <script src="http://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script> jQuery 2.x jQuery Core 2.2.4 <script src="http://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script> jQuery 1.x jQuery Core 1.12.4 <script src="http://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script> 来源: https:/

SHA256 signing stops working in .NET 4.5

瘦欲@ 提交于 2019-11-29 05:37:39
We have a piece of code which creates a SigningCredentials object to use to sign xml document by using SHA256 algorithm. It works with .NET 3.5 perfectly. However, when we upgrade our codebase to .NET 4.5, it stops working. Same code, same certificate! I have spent hours on debugging and searching on the internet without any luck. Could anyone please tell me what the problem here is? Thank you in advance. Code to create SigningCredentials: public SigningCredentials CreateSigningCredentials(X509Certificate2 cert) { var ski = new SecurityKeyIdentifier(new X509RawDataKeyIdentifierClause(cert));

在C#中的sha256加密和js中的sha256加密 C#中加密后是44位,二js或一些在线加密网站是64位,改如何选择js和C#中加密结果相同的加密算法。

走远了吗. 提交于 2019-11-29 05:01:47
C#自带的类库实现sha265会返回一个byte[] 数组 这个数组的长度是32,js的sha265是64,是把每个byte直接转换成了2个hex字符串。 C#中加密后是44位是因为把这个数组用base64编码成了字符串。 C#中也直接把byte转换成对应的hex字符串就和js中一样了。 另外,把str转换成byte[]数组的Encoding 如果不同,sha是不同的,一般js的都是utf8. public static string SHA256( string str) { //如果str有中文,不同Encoding的sha是不同的!! byte [] SHA256Data = Encoding.UTF8.GetBytes(str); SHA256Managed Sha256 = new SHA256Managed(); byte [] by = Sha256.ComputeHash(SHA256Data); return BitConverter.ToString( by ).Replace( "-" , "" ).ToLower(); //64 //return Convert.ToBase64String(by); //44 } static void Main( string [] args) { string s = "hello world" ; //sha265