/// <summary> /// Uses RNGCryptoServiceProvider to gnerate a Base64 code that is then translated to JWT format. /// </summary> /// <param name="minLength"></param> /// <param name="maxLength"></param> /// <returns></returns> public string GenerateSecretCodeUrlSafe(int minLength, int maxLength) { var length = this.RandomNumber(minLength, maxLength); var cryptoRandomDataGenerator = new RNGCryptoServiceProvider(); byte[] buffer = new byte[length]; cryptoRandomDataGenerator.GetBytes(buffer); return(JsonWebTokenUtility.Base64UrlEncodeForJson(buffer)); }
/// <summary> /// Returns a Base64 equivalent of a string created from GenerateSecretCodeUrlSafe or a JWT format. /// </summary> /// <param name="code"></param> /// <returns></returns> public string SecretCodeUrlSafeToBase64(string code) { return(JsonWebTokenUtility.UrlEncodedToBase64(code)); }