in ASP. OWIN OAuth (Microsoft.Owin.Security.OAuth), the default encryption method for access token is:
1) System.Security.Cryptography.DpapiDataProtector.Protect () 2) convert.tobase64string () 3). TrimEnd ('='). Replace ('+'-'). Replace ('/'_');
The default decryption method for access tokens is:
1) System.Security.Cryptography.DpapiDataProtector.Unprotect ()2) Pad (text. Replace ('-'+'). Replace ('_'/')); 3) convert.frombase64string ()
The implementation code of the Pad method is as follows:
Private Static stringPad (stringtext) { varpadding =3-(text. Length +3) %4); if(padding = =0) { returntext; } returnText +New string('=', padding);}
For client secret and refresh token generation, OWIN OAuth does not provide a ready-made method, we use RNGCryptoServiceProvider, the code is as follows:
RandomNumberGenerator Cryptorandomdatagenerator =NewRNGCryptoServiceProvider ();byte[] buffer =New byte[ the];cryptorandomdatagenerator.getbytes (buffer);stringSecretortoken =convert.tobase64string (buffer). TrimEnd ('='). Replace ('+','-'). Replace ('/','_');
Resources
Katana Source Code
How to generate OAuth 2 Client Id and Secret
Encryption and decryption of ASP. Oauth:access token, client secret and Refresh token generation