I m试图建造一个便携式教室,为其他班级/应用程序提供OAuth url。 这个使用OAuth的班级图书馆必须是一个便携式级图书馆,以便它能够使用DroopBox AP Im大楼的不同版本。
这一类别的一部分需要产生一种SHA1的异构体,以产生 o。
我知道,便携式班级图书馆是无支持系统。 安全。 密码是这样,这一类人能够产生一种没有这种等级的SHA1 has吗?
I m试图建造一个便携式教室,为其他班级/应用程序提供OAuth url。 这个使用OAuth的班级图书馆必须是一个便携式级图书馆,以便它能够使用DroopBox AP Im大楼的不同版本。
这一类别的一部分需要产生一种SHA1的异构体,以产生 o。
我知道,便携式班级图书馆是无支持系统。 安全。 密码是这样,这一类人能够产生一种没有这种等级的SHA1 has吗?
Mono 提供,用于管理对SHA1的实施工作。 (但如“CodeInChaos”所建议的,它并不位于Mono. Security.dll
。)
它具有开放源,经过了很好的测试,意在与微软实施完全一样(例如,它源自SHA1
,HashAlgorith
. 实施ICrypto Transform<>>/code>......),因此,它应当易于成为退约的替代物。
我认为最容易的是使用PCLCrypto nuget Pack。 然后,你可以做到:
private static string CalculateSha1Hash(string input)
{
// step 1, calculate MD5 hash from input
var hasher = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha1);
byte[] inputBytes = Encoding.UTF8.GetBytes(input);
byte[] hash = hasher.HashData(inputBytes);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
sb.Append(hash[i].ToString("X2"));
}
return sb.ToString();
}
我非常需要这一点,而且我发现从哈希里卜(http://hashlib.codeplex.com/)处执行《公约》。
Mono implementation have some far-going dependencies (localization of exceptions, etc.), while from HashLib you need only to copy few files without any changes in them:
Converters.cs
Hash.cs
HashBuffer.cs
HashCryptoNotBuildIn.cs
HashResult.cs
IHash.cs
SHA0.cs
SHA1.cs
55 KB of code total, so nothing too heavy.
我使用了这一丛书:。 https://www.nuget.org/ Packages/BouncyCastle-PCL/。 并且对我只做罚款(横跨平台Windows Store App, .Net Framework 4.5,银光5,Windows 8,Xamarin.Android, Xamarin.iOS)。
利用HMACSHA1号这样的签名:
public string GenerateSignature(string key, string signatureBase)
{
var keyBytes = Encoding.UTF8.GetBytes(key);
HMACSHA1 hashAlgorithm = new HMACSHA1(keyBytes);
byte[] dataBuffer = Encoding.UTF8.GetBytes(signatureBase);
byte[] hashBytes = hashAlgorithm.ComputeHash(dataBuffer);
return Convert.ToBase64String(hashBytes);
}
SHA-1 Wikipedia article 载有可用作您本人执行的指南的假编码。 但是,与始终具有加密功能一样,我强烈建议使用经过试验和测试的实施。
假设你希望实施《公约》第256条,你可在BouncyCastle上找到一个,以源代码形式提供。 相关类别称为Org.BouncyCastle.Crypto.Digests。 Sha256Digest(其source/a)。
您不妨检查新的<>。 NET 标准图书馆:
该编码是便携式的,并包含<代码>System. Security.Cryptography。
/// <summary>
/// Compute hash for string encoded as UTF8
/// </summary>
/// <param name="input">String to be hashed.</param>
/// <returns>40-character hex string.</returns>
public static string GetSha1(string input)
{
using (var sha1 = System.Security.Cryptography.SHA1.Create())
{
byte[] inputBytes = Encoding.UTF8.GetBytes(input);
byte[] hash = sha1.ComputeHash(inputBytes);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
sb.Append(hash[i].ToString("X2"));
}
return sb.ToString();
}
}
你们还可以在这方面得到一些帮助(与网络标准图书馆一起创建个人电脑项目):
这方面的一个例子是BouncyCastle 。
public static string ComputeSha1(string data)
{
var sha1Digest = new Org.BouncyCastle.Crypto.Digests.Sha1Digest();
var hash = new byte[sha1Digest.GetDigestSize()];
var dataBytes = Encoding.UTF8.GetBytes(data);
foreach (var b in dataBytes)
{
sha1Digest.Update(b);
}
sha1Digest.DoFinal(hash, 0);
return string.Join("", hash.Select(b => b.ToString("x2")).ToArray());
}
我也希望签署奥阿特,并且正在研究PCL的密码——这一测试表明,HmacSha1'h的形成,并将结果与标准进行比较。 NET Framework way.
[Test]
public void CreateHash_VersusComputeHash_ReturnsEquivalent()
{
// USING TRADITIONAL .NET:
var key = new byte[32];
var contentBytes = Encoding.UTF8.GetBytes("some kind of content to hash");
new RNGCryptoServiceProvider().GetBytes(key);
var alg = new HMACSHA1(key); // Bouncy castle usage does not differ from this
var result = alg.ComputeHash(contentBytes);
// USING PCL CRYPTO:
var algorithm = WinRTCrypto.MacAlgorithmProvider.OpenAlgorithm(MacAlgorithm.HmacSha1);
byte[] mac;
using (var hasher = algorithm.CreateHash(key))
{
hasher.Append(contentBytes);
mac = hasher.GetValueAndReset();
}
// Assert results:
Assert.AreEqual(result.Length, mac.Length);
for (var i = 0; i < result.Length; i++)
{
Assert.AreEqual(result[i], mac[i]);
}
}
当我不得不取得同样结果时,我就这样做了。 您也可通过<代码>SHA512及其他方式来做到这一点。
using System.Security.Cryptography;
public static string HashSHA1(this string value)
{
using (var sha = SHA1.Create())
{
return Convert.ToBase64String(sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes(value)));
}
}
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...
I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber. I want to create a many to many association ...
How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...
Since I cannot order my dictionary, what is the best way of going about taking key value pairs and also maintaing an index?
Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...