当前位置: 首页>>代码示例>>C#>>正文


C# RNGCryptoServiceProvider.Create256BitLowerCaseHexKey方法代码示例

本文整理汇总了C#中System.Security.Cryptography.RNGCryptoServiceProvider.Create256BitLowerCaseHexKey方法的典型用法代码示例。如果您正苦于以下问题:C# RNGCryptoServiceProvider.Create256BitLowerCaseHexKey方法的具体用法?C# RNGCryptoServiceProvider.Create256BitLowerCaseHexKey怎么用?C# RNGCryptoServiceProvider.Create256BitLowerCaseHexKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.Cryptography.RNGCryptoServiceProvider的用法示例。


在下文中一共展示了RNGCryptoServiceProvider.Create256BitLowerCaseHexKey方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetEncryptedNoteKey

        private string GetEncryptedNoteKey(DBNote note)
        {
            // re-use the same key when saving a note
            string encrypted_per_note_key;

            var saved_note = db.FirstOrDefault<DBNote> (n => n.CompoundPrimaryKey == note.CompoundPrimaryKey);
            if (saved_note != null) {
                encrypted_per_note_key = saved_note.EncryptedKey;
            } else {
                // new note, generate a new key
                var rng = new RNGCryptoServiceProvider ();
                encrypted_per_note_key = rng.Create256BitLowerCaseHexKey ().EncryptWithKey (encryptionMasterKey, User.MasterKeySalt);
            }
            return encrypted_per_note_key;
        }
开发者ID:rashoodkhan,项目名称:Rainy,代码行数:15,代码来源:DbEncryptedStorage.cs

示例2: CreateCryptoFields

        public static void CreateCryptoFields(this DBUser db_user, string password)
        {
            if (string.IsNullOrEmpty (password))
                throw new ArgumentNullException ("password");

            var rng = new RNGCryptoServiceProvider ();

            var salt = rng.Create256BitLowerCaseHexKey ();
            db_user.PasswordSalt = salt.Substring (0, 32);
            db_user.MasterKeySalt = salt.Substring (32, 32);

            db_user.UpdatePassword (password);

            // generate master key - always fix and will sustain password changes
            string master_key = rng.Create256BitLowerCaseHexKey ();
            var pw_key = db_user.DeriveKeyFromPassword (password);

            // now encrypt the cleartext masterkey with the password-derived key
            using (var aes = new AesManaged ()) {
                ICryptoTransform encryptor = aes.CreateEncryptor(pw_key, db_user.MasterKeySalt.ToByteArray ());
                // Create the streams used for encryption.
                using (MemoryStream msEncrypt = new MemoryStream())
                {
                    using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
                    {
                        using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
                        {

                            //Write all data to the stream.
                            swEncrypt.Write(master_key);
                        }
                        var encrypted = msEncrypt.ToArray();
                        db_user.EncryptedMasterKey = encrypted.ToHexString ();
                    }
                }
            }
        }
开发者ID:Dynalon,项目名称:Rainy,代码行数:37,代码来源:Crypto.cs

示例3: TokenExchangeAfterAuthentication

        public object TokenExchangeAfterAuthentication(string username, string password, string token)
        {
            var response = new OAuthAuthenticateResponse ();
            var rng = new RNGCryptoServiceProvider ();

            // TODO surround with try/catch and present 403 or 400 if token is unknown/invalid
            var request_token = oauthHandler.RequestTokens.GetToken (token);

            // the verifier is important, it is proof that the user successfully authorized
            // the verifier is later tested by the OAuth10aInspector to macht
            request_token.Verifier = rng.Create256BitLowerCaseHexKey ();
            request_token.AccessDenied = false;

            var access_token = GenerateAccessToken (username, password);
            request_token.AccessToken = access_token;

            oauthHandler.RequestTokens.SaveToken (request_token);
            Logger.DebugFormat ("created an access token for user {0}: {1}", username, token);

            // redirect to the provded callback
            var redirect_url = request_token.CallbackUrl + "?oauth_verifier=" + request_token.Verifier
                + "&oauth_token=" + request_token.Token;

            response.RedirectUrl = redirect_url;

            // the browser/gateway page should take the RedirectUrl and access it
            // note that the redirect url points to a tomboy listener, or tomdroid listener (tomdroid://...)
            return response;
        }
开发者ID:Dynalon,项目名称:Rainy,代码行数:29,代码来源:OAuthService.cs

示例4: GenerateAccessToken

        private AccessToken GenerateAccessToken(string username, string password, DateTime? expiry = null)
        {
            if (!expiry.HasValue)
                expiry = DateTime.Now.AddYears (99);

            var rng = new RNGCryptoServiceProvider ();
            string access_token_secret = rng.Create256BitLowerCaseHexKey ();
            string token_key = rng.Create256BitLowerCaseHexKey ();

            // the token is the master key encrypted with the token key
            string access_token_token;
            using (var db = connFactory.OpenDbConnection ()) {
                DBUser user = db.First<DBUser> (u => u.Username == username);
                string master_key = user.GetPlaintextMasterKey (password).ToHexString ();
                access_token_token = master_key.EncryptWithKey (token_key, user.MasterKeySalt);
            }

            var access_token = new AccessToken () {
                ConsumerKey = "anyone",
                Realm = "Rainy",
                Token = access_token_token,
                TokenSecret = access_token_secret,
                UserName = username,
                ExpiryDate = expiry.Value
            };
            access_token.SetTokenKey (token_key);
            return access_token;
        }
开发者ID:Dynalon,项目名称:Rainy,代码行数:28,代码来源:OAuthService.cs

示例5: CreateRequestToken

        public IToken CreateRequestToken(IOAuthContext context)
        {
            if (context == null) throw new ArgumentNullException("context");

            // for request tokens, 128 bit entropy should be enough
            var rng = new RNGCryptoServiceProvider ();
            var key = rng.Create256BitLowerCaseHexKey ();
            var token_rnd = key.Substring(0, 32);
            var token_secret = key.Substring(32, 32);

            var token = new RequestToken
            {
                ConsumerKey = context.ConsumerKey,
                Realm = context.Realm,
                Token = token_rnd,
                TokenSecret = token_secret,
                CallbackUrl = context.CallbackUrl
            };

            _requestTokenRepository.SaveToken(token);

            return token;
        }
开发者ID:Dynalon,项目名称:Rainy,代码行数:23,代码来源:OAuthStores.cs


注:本文中的System.Security.Cryptography.RNGCryptoServiceProvider.Create256BitLowerCaseHexKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。