Ejemplo n.º 1
0
        // signature
        public static string CreateSignature(string email, string password, RSAParameters key)
        {
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();

            rsa.ImportParameters(key);
            SHA1 sha1 = SHA1.Create();

            byte[] prefix    = { 0x00 };
            byte[] hash      = sha1.ComputeHash(GoogleKeyUtils.KeyToStruct(key)).Take(4).ToArray();
            byte[] encrypted = rsa.Encrypt(Encoding.UTF8.GetBytes(email + "\x00" + password), true);
            return(DataTypeUtils.UrlSafeBase64(DataTypeUtils.CombineBytes(prefix, hash, encrypted)));
        }
Ejemplo n.º 2
0
        // signature
        public static string CreateSignature(string email, string password, RSAParameters key)
        {
            var rsa       = AsymmetricKeyAlgorithmProvider.OpenAlgorithm(AsymmetricAlgorithmNames.RsaOaepSha1);
            var keyBlob   = CryptographicBuffer.DecodeFromBase64String(b64KeyBlob);
            var publicKey = rsa.ImportPublicKey(keyBlob, CryptographicPublicKeyBlobType.Capi1PublicKey);

            byte[] prefix = { 0x00 };
            HashAlgorithmProvider hashAlgorithm = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha1);
            var hash = hashAlgorithm.HashData(GoogleKeyUtils.KeyToStruct(key).AsBuffer()).ToArray().Take(4).ToArray();

            byte[] encrypted = CryptographicEngine.Encrypt(publicKey, Encoding.UTF8.GetBytes(email + "\x00" + password).AsBuffer(), null).ToArray();
            return(DataTypeUtils.UrlSafeBase64(DataTypeUtils.CombineBytes(prefix, hash, encrypted)));
        }