/// <summary> /// md5加密 /// </summary> /// <param name="str">要加密字符串</param> /// <returns>加密后密码</returns> private string get_MD5(string str) { Windows.Security.Cryptography.Core.HashAlgorithmProvider objAlgProv = Windows.Security.Cryptography.Core.HashAlgorithmProvider.OpenAlgorithm(Windows.Security.Cryptography.Core.HashAlgorithmNames.Md5); Windows.Security.Cryptography.Core.CryptographicHash md5 = objAlgProv.CreateHash(); Windows.Storage.Streams.IBuffer buffMsg1 = Windows.Security.Cryptography.CryptographicBuffer.ConvertStringToBinary(str, Windows.Security.Cryptography.BinaryStringEncoding.Utf16BE); md5.Append(buffMsg1); Windows.Storage.Streams.IBuffer buffHash1 = md5.GetValueAndReset(); return(Windows.Security.Cryptography.CryptographicBuffer.EncodeToBase64String(buffHash1)); //System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); //byte[] temp; //StringBuilder strb = new StringBuilder(); //temp = md5.ComputeHash(Encoding.Unicode.GetBytes(str)); //md5.Clear(); //for (int i = 0; i < temp.Length; i++) //{ // strb.Append(temp[i].ToString("X").PadLeft(2 , '0')); //} //return strb.ToString().ToLower(); }
public async System.Threading.Tasks.Task <string> ReadCDDiscid(string Id) { string result = string.Empty; var customDevice = await Windows.Devices.Custom.CustomDevice.FromIdAsync(Id, DeviceAccessMode.ReadWrite, DeviceSharingMode.Exclusive); if (customDevice != null) { try { TOCTrack[] SectorArray = await GetCDSectorArray(customDevice); if ((SectorArray != null) && (SectorArray.Length > 1)) { // SHA-1 // first track Windows.Security.Cryptography.Core.HashAlgorithmProvider sha1 = Windows.Security.Cryptography.Core.HashAlgorithmProvider.OpenAlgorithm(Windows.Security.Cryptography.Core.HashAlgorithmNames.Sha1); if (sha1 != null) { // SHA-1 // first track int track = 1; int lastIndex = SectorArray.Length - 1; for (int i = 0; i < SectorArray.Length; i++) { if (SectorArray[i].bData == true) { lastIndex = i; break; } } string stringToEncod = string.Format("{0:X2}", track); track = lastIndex; stringToEncod += string.Format("{0:X2}", track); if (lastIndex == (SectorArray.Length - 1)) { stringToEncod += string.Format("{0:X8}", SectorArray[lastIndex].Position + 150); } else { stringToEncod += string.Format("{0:X8}", SectorArray[lastIndex].Position + 150 - 11400); } for (int i = 0; i < 99; i++) { if (i < (lastIndex)) { stringToEncod += string.Format("{0:X8}", SectorArray[i].Position + 150); } else { stringToEncod += "00000000"; } } Windows.Storage.Streams.IBuffer buffer = Windows.Security.Cryptography.CryptographicBuffer.ConvertStringToBinary(stringToEncod, Windows.Security.Cryptography.BinaryStringEncoding.Utf8); Windows.Storage.Streams.IBuffer hashBuffer = sha1.HashData(buffer); result = Windows.Security.Cryptography.CryptographicBuffer.EncodeToBase64String(hashBuffer); // Update to be compliant with MusicBrainz result = result.Replace('+', '.'); result = result.Replace('/', '_'); result = result.Replace('=', '-'); result += "?inc=artists+recordings&toc=1+" + lastIndex.ToString() + "+"; if (lastIndex == (SectorArray.Length - 1)) { result += (SectorArray[lastIndex].Position + 150).ToString(); } else { result += (SectorArray[lastIndex].Position + 150 - 11400).ToString(); } for (int i = 0; i < lastIndex; i++) { result += "+" + (SectorArray[i].Position + 150).ToString(); } } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception while reading Media Metadata: " + ex.Message); result = string.Empty; } } return(result); }
/// <summary> /// Initializes a new instance of the <see cref="HashAlgorithmProvider" /> class. /// </summary> /// <param name="algorithm">The algorithm.</param> internal HashAlgorithmProvider(HashAlgorithm algorithm) { this.algorithm = algorithm; this.platform = Platform.Core.HashAlgorithmProvider.OpenAlgorithm(GetAlgorithmName(algorithm)); }