private byte [] _GetRandomBytes(byte[] seed) { IntPtr prov; bool retVal = WinCeApi.CryptAcquireContext(out prov, null, null, (int)WinCeApi.SecurityProviderType.RSA_FULL, 0); retVal = _CryptGenRandom(prov, seed.Length, seed); WinCeApi.CryptReleaseContext(prov, 0); return(seed); }
private bool _CryptGenRandom(IntPtr hProv, int dwLen, byte[] pbBuffer) { if (System.Environment.OSVersion.Platform == PlatformID.WinCE) { return(WinCeApi.CryptGenRandomCe(hProv, dwLen, pbBuffer)); } else { return(WinCeApi.CryptGenRandomXp(hProv, dwLen, pbBuffer)); } }
/// <summary> /// omputes the MD5 hash value for the specified byte array. /// </summary> /// <param name="pass">The input for which to compute the hash code.</param> /// <returns>The computed hash code.</returns> public static byte[] MD5Hash(byte[] pass) { IntPtr hProv; bool retVal = WinCeApi.CryptAcquireContext(out hProv, null, null, (int)WinCeApi.SecurityProviderType.RSA_FULL, 0); IntPtr hHash; retVal = WinCeApi.CryptCreateHash(hProv, (int)WinCeApi.SecurityProviderType.CALG_MD5, IntPtr.Zero, 0, out hHash); byte [] publicKey = pass; int publicKeyLen = publicKey.Length; retVal = WinCeApi.CryptHashData(hHash, publicKey, publicKeyLen, 0); int bufferLen = 16; // SHA1 size byte [] buffer = new byte[bufferLen]; retVal = WinCeApi.CryptGetHashParam(hHash, (int)WinCeApi.SecurityProviderType.HP_HASHVAL, buffer, ref bufferLen, 0); retVal = WinCeApi.CryptDestroyHash(hHash); retVal = WinCeApi.CryptReleaseContext(hProv, 0); return(buffer); }