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); }
// <summary> /// return a SHA1 Hash on PPC and Smartphone /// </summary> /// <param name="pass"></param> /// <returns></returns> public static byte[] Sha1Hash(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_SHA1, IntPtr.Zero, 0, out hHash); byte [] publicKey = pass; int publicKeyLen = publicKey.Length; retVal = WinCeApi.CryptHashData(hHash, publicKey, publicKeyLen, 0); int bufferLen = 20; // 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); }