Tag: hash

无法为UnsafeMutablePointer <UInt8>types调用初始化程序

我试图将我的string转换为SHA256哈希,但我得到了下一个错误: Cannot invoke initializer for type 'UnsafeMutablePointer<UInt8>' with an argument list of type '(UnsafeMutableRawPointer)' 这是我的function: func SHA256(data: String) -> Data { var hash = NSMutableData(length: Int(CC_SHA256_DIGEST_LENGTH))! if let newData: Data = data.data(using: .utf8) { let bytes = newData.withUnsafeBytes {(bytes: UnsafePointer<CChar>) -> Void in CC_SHA256(bytes, CC_LONG(newData.length), UnsafeMutablePointer<UInt8>(hash.mutableBytes)) } } return hash as Data } 所以,这部分 UnsafeMutablePointer<UInt8>(hash.mutableBytes) […]

大数字的SHA256散列结果在Android和iOS上不同

我试图哈希一个BigInteger / BigNum,我在Android / iOS获得不同的结果。 我需要获得相同的散列结果,以便两个应用程序按照SRP协议工作。 仔细观察,它对正数工作正常,但对负数不起作用(第一个半字节大于7)。 不知道哪一个是正确的,哪一个是要调整到与另一个匹配的。 安卓: void hashBigInteger(String s) { try { BigInteger a = new BigInteger(s, 16); MessageDigest sha = MessageDigest.getInstance("SHA-256"); byte[] b = a.toByteArray(); sha.update(b, 0, b.length); byte[] digest = sha.digest(); BigInteger d = new BigInteger(digest); Log.d("HASH", "H = " + d.toString(16)); } catch (NoSuchAlgorithmException e) { throw new UnsupportedOperationException(e); […]

在Objective-C和C#.NET中产生不同结果的SHA1哈希

基本上我想编写计算sha1哈希函数。 到目前为止我已经尝试了如下。 C#.NET byte[] p2 = System.Text.Encoding.Unicode.GetBytes("password"); System.Security.Cryptography.SHA1 sha = new System.Security.Cryptography.SHA1CryptoServiceProvider(); byte[] result = sha.ComputeHash(p2); string encodedPassword = Convert.ToBase64String(result); 输出: 6Pl / upEE0epQR5SObftn + s2fW3M = Objective-C的 我从NSData_Base64类引用添加了Base64的类 。 NSString *password = @"password"; NSData *data = [password dataUsingEncoding:NSUTF8StringEncoding]; NSString *unicodePassword = [[NSString alloc] initWithData:data encoding:NSUnicodeStringEncoding]; data = [unicodePassword dataUsingEncoding:NSUnicodeStringEncoding]; unsigned char hash[CC_SHA1_DIGEST_LENGTH]; CC_SHA1([data bytes], […]