freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

oauth2學(xué)習(xí)及dotnetopenauth部分源碼研究-資料下載頁

2025-06-24 18:59本頁面
  

【正文】 var writer = new BinaryWriter(finalStream)。 30 if () 31 { 32 ()。 33 } 34 35 (encoded)。 36 ()。 37 38 string payload = (())。 39 string result = payload。 40 if (symmetricSecretHandle != null amp。amp。 ( || )) 41 { 42 result = (symmetricSecretHandle, payload)。 43 } 44 45 return result。 46 } 47 } 代碼第5行,生成一個Nonce隨機(jī)數(shù)并保存在消息中,public static class MessagingUtilities { internal static Random NonCryptoRandomDataGenerator { get { return 。 } } internal static byte[] GetNonCryptoRandomData(int length) { byte[] buffer = new byte[length]。 (buffer)。 return buffer。 } } private static class ThreadSafeRandom { [ThreadStatic] private static Random threadRandom。 public static Random RandomNumberGenerator { get { if (threadRandom == null) { lock (threadRandomInitializer) { threadRandom = new Random(())。 } } return threadRandom。 } } } 第12行將流壓縮,采用Deflate或Gzip壓縮internal static byte[] Compress(byte[] buffer, CompressionMethod method = ) { using (var ms = new MemoryStream()) { Stream pressingStream = null。 try { switch (method) { case : pressingStream = new DeflateStream(ms, , true)。 break。 case : pressingStream = new GZipStream(ms, , true)。 break。 } (buffer, 0, )。 return ()。 } finally { if (pressingStream != null) { ()。 } } } } 第18行進(jìn)行加密并獲取可能的隨機(jī)生成的對稱加密密鑰private byte[] Encrypt(byte[] value, out string symmetricSecretHandle) { if ( != null) { symmetricSecretHandle = null。 return (value)。 } else { var cryptoKey = (, )。 symmetricSecretHandle = 。 return (value, )。 } } 如果使用非對稱加密,internal static byte[] EncryptWithRandomSymmetricKey(this RSACryptoServiceProvider crypto, byte[] buffer)。 如果使用對稱加密,則調(diào)用GetCurrentKey方法internal static KeyValuePairstring, CryptoKey GetCurrentKey(this ICryptoKeyStore cryptoKeyStore, string bucket, TimeSpan minimumRemainingLife, int keySize = 256) { var cryptoKeyPair = (bucket).FirstOrDefault(pair = == keySize / 8)。 if ( == null || + minimumRemainingLife) { ... byte[] secret = GetCryptoRandomData(keySize / 8)。 DateTime expires = + SymmetricSecretKeyLifespan。 var cryptoKey = new CryptoKey(secret, expires)。 string handle = GetRandomString(SymmetricSecretHandleLength, Base64WebSafeCharacters)。 cryptoKeyPair = new KeyValuePairstring, CryptoKey(handle, cryptoKey)。 (bucket, handle, cryptoKey)。 ... } } internal static readonly RandomNumberGenerator CryptoRandomDataGenerator = new RNGCryptoServiceProvider()。 internal static byte[] GetCryptoRandomData(int length) { byte[] buffer = new byte[length]。 (buffer)。 return buffer。 } internal static string GetRandomString(int length, string allowableCharacters) { char[] randomString = new char[length]。 var random = NonCryptoRandomDataGenerator。 for (int i = 0。 i length。 i++) { randomString[i] = allowableCharacters[()]。 } return new string(randomString)。 } 可以看到,://localhost/dnoa/oauth_authorization_code,刷新令牌的是://localhost/dnoa/. ,密碼雖然也是隨機(jī)生成的,. 如果對稱加密密鑰是新生成的,則會將相關(guān)信息保存至數(shù)據(jù)庫. 獲取到對稱加密密鑰后,使用MessagingUtilities類的Encrypt方法加密數(shù)據(jù)流.internal static byte[] Encrypt(byte[] buffer, byte[] key) { using (SymmetricAlgorithm crypto = CreateSymmetricAlgorithm(key)) { ... } } private static SymmetricAlgorithm CreateSymmetricAlgorithm(byte[] key) { SymmetricAlgorithm result = null。 try { result = new RijndaelManaged()。 = 。 = key。 return result。 } catch { ... } } 可以看到,對稱加密使用的是SymmetricAlgorithm類. 第23行對加密后的數(shù)據(jù)進(jìn)行數(shù)字簽名private byte[] CalculateSignature(byte[] bytesToSign, string symmetricSecretHandle) { if ( != null) { using (var hasher = ()) { return (bytesToSign, hasher)。 } } else { var key = (, symmetricSecretHandle)。 using (var symmetricHasher = (, )) { return (bytesToSign)。 } } } 如果是非對稱加密,則使用Sha1進(jìn)行簽名,internal static class HmacAlgorithms { internal const string HmacSha1 = HMACSHA1。 internal const string HmacSha256 = HMACSHA256。 internal const string HmacSha384 = HMACSHA384。 internal const string HmacSha512 = HMACSHA512。 internal static HMAC Create(string algorithmName, byte[] key) { (algorithmName, algorithmName)。 (key, key)。 HMAC hmac = (algorithmName)。 try { = key。 return hmac。 } catch { if CLR4 ()。 endif throw。 } } } 第26到36行,把可能的數(shù)字簽名放在加密流的前面. 第38行將二進(jìn)制流轉(zhuǎn)換成Base64字符流. 第40到第43行,如果對稱加密名不為空,且使用了對稱加密或簽名,則將加密名放到字符流前面.internal static string CombineKeyHandleAndPayload(string handle, string payload) { return handle + ! + payload。 } 反序列化過程大致與之相反1 public void Deserialize(T message, string value, IProtocolMessage containingMessage, string messagePartName) 2 { 3 string symmetricSecretHandle = null。 4 if ( amp。amp。 != null) 5 { 6 string valueWithoutHandle。 7 (messagePartName, value, out symmetricSecretHandle, out valueWithoutHandle)。 8 value = valueWithoutHandle。 9 } 10 11 = containingMessage。 12 byte[] data = (value)。 13 14 byte[] signature = null。 15 if () 16 { 17 using (var dataStream = new MemoryStream(data)) 18 { 19 var dataReader = new BinaryReader(dataStream)。 20 signature = (1024)。 21 data = (8 * 1024)。 22 } 23 24 // Verify that the verification code was issued by message authorization server. 25 ((data, signature, symmetricSecretHandle), )。 26 } 27 28 if () 29 { 30 data = (data, symmetricSecretHandle)。 31 } 32 33 if () 34 { 35 data = (data)。 36 } 37 38 (message, data)。 39 = signature。 // TODO: we don39。t really need this any more, do we? 40 41 if () 42 { 43 // Has message verification code expired? 44 DateTime expirationDate = + 。 45 if (expirationDate ) 46 { 47 throw new ExpiredMessageException(expirationDate, containingMessage)。 48 } 49 } 50 51 // Has message verification code already been used to obtain an access/refresh token? 52 if ( != null) 53 { 54 (, Oops! How can we validate a nonce without a maximum message age?)。 55 string context = { + GetType().FullName + }。 56 if (!(context, (), )) 57 { 58 (Replayed nonce detected ({0} {1}). Rejecting message., , )。 59 throw new ReplayedMessageException(containingMessage)。 60 } 61 } 62 63 ((IMessage)message).EnsureValidMessage()。 64 } 第4到第9行將可能的對稱密碼名稱與Base64加密字符流分開 第12行將Base64字符串還原成二進(jìn)制流 第15到第26行驗(yàn)證數(shù)字簽名private bool IsSignatureValid(
點(diǎn)擊復(fù)制文檔內(nèi)容
環(huán)評公示相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1