<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ravi Ranjan Pandey</title>
    <description>The latest articles on DEV Community by Ravi Ranjan Pandey (@raviranjanpandey).</description>
    <link>https://dev.to/raviranjanpandey</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F592279%2F1a868c57-f7df-40c5-9000-3efe9514f491.jpeg</url>
      <title>DEV Community: Ravi Ranjan Pandey</title>
      <link>https://dev.to/raviranjanpandey</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/raviranjanpandey"/>
    <language>en</language>
    <item>
      <title>Setting Android Emulator in an AMD Powered Computer using Visual Studio 2022</title>
      <dc:creator>Ravi Ranjan Pandey</dc:creator>
      <pubDate>Mon, 14 Feb 2022 05:09:33 +0000</pubDate>
      <link>https://dev.to/raviranjanpandey/setting-android-emulator-in-an-amd-powered-computer-using-visual-studio-2022-4a6h</link>
      <guid>https://dev.to/raviranjanpandey/setting-android-emulator-in-an-amd-powered-computer-using-visual-studio-2022-4a6h</guid>
      <description>&lt;p&gt;If you are a xamarin mobile app developer and currently setting up android emulator on a windows 10 or windows 11 machine running on AMD Processor, then this article can help you to save some time and efforts while setting up the android emulator.&lt;/p&gt;

&lt;p&gt;In a normal installation process we need to select tools for xamarin app development and install it. For launching the emulator create a project for android mobile app and go to &lt;br&gt;
&lt;strong&gt;Tools-&amp;gt;Android-&amp;gt;Android Device Manager&lt;/strong&gt;&lt;br&gt;
Click on New Button and Create a Google Pixel Device with latest android version and Click Start.&lt;/p&gt;

&lt;p&gt;If you don't get any errors and the Emulator runs smoothly then congratulations you have made it else don't worry this article can help you with few workarounds to keep emulator up and running.&lt;/p&gt;

&lt;p&gt;First step is to check if Windows Hypervisor Platform option is checked in the &lt;strong&gt;Turn Windows Features on or off&lt;/strong&gt; screen in control panel.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oAk7m5Rk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/djt8g2eal3zrnb5wlnb9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oAk7m5Rk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/djt8g2eal3zrnb5wlnb9.png" alt="Enable Windows Hypervisor Platform" width="591" height="635"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we need to enable Hardware acceleration for AMD Processor. Go to Android SDK Manager(Tools-&amp;gt;Android-&amp;gt;Android SDK Manager)&lt;br&gt;
Click on Tools Tab and Extras Menu. Check Android Emulator Hypervisor Driver for AMD Processors(installer) and install it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VhfOrUjl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eianuq4a3sqm0perb1gy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VhfOrUjl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eianuq4a3sqm0perb1gy.png" alt="Enable Hardware acceleration" width="880" height="902"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Restart the System and Try to launch the Android Emulator it should start smoothly. But in case you did not get success keep exploring further and create another article describing the fix.&lt;/p&gt;

&lt;p&gt;Happy Coding!&lt;/p&gt;

</description>
      <category>xamarin</category>
      <category>maui</category>
      <category>vs2022</category>
      <category>android</category>
    </item>
    <item>
      <title>Create a Web Api using Minimal Api in .NET 6</title>
      <dc:creator>Ravi Ranjan Pandey</dc:creator>
      <pubDate>Sun, 13 Feb 2022 06:51:55 +0000</pubDate>
      <link>https://dev.to/raviranjanpandey/create-a-web-api-using-minimal-api-in-net-6-1b2a</link>
      <guid>https://dev.to/raviranjanpandey/create-a-web-api-using-minimal-api-in-net-6-1b2a</guid>
      <description>&lt;p&gt;&lt;strong&gt;.NET 6&lt;/strong&gt; brings many language improvements in C# 10. Minimal Api is one such feature which allows to create a web api with less boilerplate code. Here is the example which uses Minimal Api for creating an AES Encryption and Decryption api.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using AESEncryptDecrypt;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.MapPost("/encrypt", (string value) =&amp;gt;
{
    string key = app.Configuration["AES:Key"];
    string iv = app.Configuration["AES:AES_IV"];
    return Results.Ok(AESEncDec.AESEncryption(value, key, iv));
});
app.MapPost("/decrypt", (string value) =&amp;gt;
{
    string key = app.Configuration["AES:Key"];
    string iv = app.Configuration["AES:AES_IV"];
    return Results.Ok(AESEncDec.AESDecryption(value, key, iv));
});

app.Run();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Full Code can be found here on &lt;a href="https://github.com/raviranjanpandey/aesencdec"&gt;Github&lt;/a&gt;&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>minimalapi</category>
      <category>net6</category>
      <category>webapi</category>
    </item>
    <item>
      <title>How to securely send/receive key params in an .NET Core WebAPI and Javascript Application</title>
      <dc:creator>Ravi Ranjan Pandey</dc:creator>
      <pubDate>Wed, 14 Jul 2021 08:05:41 +0000</pubDate>
      <link>https://dev.to/raviranjanpandey/how-to-securely-send-receive-key-params-in-net-core-webapi-and-javascript-2d5b</link>
      <guid>https://dev.to/raviranjanpandey/how-to-securely-send-receive-key-params-in-net-core-webapi-and-javascript-2d5b</guid>
      <description>&lt;p&gt;In an api its common to have some identifier keys to identify user details and process data accordingly. Its also common to take these details from either query parameters or headers or route path from client side.&lt;br&gt;
However these apis will be rejected in the security audit process as they expose user data and has insecure object reference vulnerability, which can be maliciously exploited to get information of other users by tweaking these api parameters.&lt;br&gt;
There are many ways to handle this security issue, however in this tutorial i will explain how to handle this by encrypting these params together into a single key and sending that in a header. I will also explain how to handle it at the api level using a middleware in .NET Core Api. Encryption is done in javascript to use in a client application and decryption is done in C# at the API level. &lt;br&gt;
I have used AES Key-Based Encryption algorithm to achieve encryption and decryption.&lt;/p&gt;

&lt;p&gt;Lets assume we have an salaries api with employeeid as param&lt;/p&gt;

&lt;p&gt;&lt;code&gt; api/salaries/getbyemployeeid?employeeid=1031 &lt;/code&gt;&lt;/p&gt;

&lt;p&gt;in this api, we are exposing an important key identifier employeeid and hence its exposed because anyone with some basic authentication can check details of another employee to avoid this first we will remove the query parameter.&lt;/p&gt;

&lt;p&gt;&lt;code&gt; api/salaries/getbyemployeeid &lt;/code&gt;&lt;/p&gt;

&lt;p&gt;next we will generate an encrypted key using AES Encryption and then we will send that key as header.&lt;/p&gt;

&lt;p&gt;&lt;b&gt; Encryption in JavaScript &lt;/b&gt;&lt;/p&gt;

&lt;p&gt;install the package &lt;code&gt;npm install crypto-js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const CryptoJS = require('crypto-js');
function Encrypt(str) {
                 var KEY = "12345678900000001234567890000000";//32 bit
                 var IV = "1234567890000000";//16 bits
        var key = CryptoJS.enc.Utf8.parse(KEY);
        var iv = CryptoJS.enc.Utf8.parse(IV);

        var encrypted = '';

        var srcs = CryptoJS.enc.Utf8.parse(str);
        encrypted = CryptoJS.AES.encrypt(srcs, key, {
            iv: iv,
            mode: CryptoJS.mode.CBC,
            padding: CryptoJS.pad.Pkcs7
        });

        return encrypted.ciphertext.toString();
    }
var encryptedEmployeeId = Encrypt("1031");
console.log(encryptedEmployeeId);
//result would be EF082204BF6F804099396A96CC7733F4

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;b&gt; Decryption in C# &lt;/b&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
public class EncryptDecrypt
{
    public static string AESDecryption(string input)
    {
        string AES_IV = "1234567890000000";//16 bits 
        string key = "12345678900000001234567890000000"; //32 bits
        byte[] inputBytes = HexStringToByteArray(input);
            byte[] keyBytes = Encoding.UTF8.GetBytes(key.Substring(0, 32));
            using AesCryptoServiceProvider aesAlg = new AesCryptoServiceProvider();
            aesAlg.Key = keyBytes;
            aesAlg.IV = Encoding.UTF8.GetBytes(AES_IV.Substring(0, 16));

            ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
            using MemoryStream msEncrypt = new MemoryStream(inputBytes);
            using CryptoStream csEncrypt = new CryptoStream(msEncrypt, decryptor, CryptoStreamMode.Read);
            using StreamReader srEncrypt = new StreamReader(csEncrypt);
            return srEncrypt.ReadToEnd();
    }

private static byte[] HexStringToByteArray(string s)
        {
            s = s.Replace(" ", "");
            byte[] buffer = new byte[s.Length / 2];
            for (int i = 0; i &amp;lt; s.Length; i += 2)
                buffer[i / 2] = (byte)Convert.ToByte(s.Substring(i, 2), 16);
            return buffer;
        }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;b&gt; Send encrypted param in the header &lt;/b&gt;&lt;br&gt;
I added a header named Request-Id &lt;br&gt;
&lt;code&gt;Request-Id : EF082204BF6F804099396A96CC7733F4&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt; Adding a Request Middleware to grab the header value and Decrypt it. &lt;/b&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
public class RequestMiddleware
    {
        private readonly RequestDelegate _next;
        public RequestMiddleware(RequestDelegate next)
        {
            _next = next;
        }
        public async Task Invoke(HttpContext context)
        {
            if (context.Request.Headers.TryGetValue("Request-Id", out var requestid))
            {
                var employeeid = EncryptDecrypt.AESDecryption(requestid);     
            }

            await _next(context);
        }
    }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Configure the Middleware before the middleware used for other apis to make it available and can be saved in a static variable.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;app.UseMiddleware(typeof(RequestMiddleware));&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt; Conclusion &lt;/b&gt;&lt;br&gt;
So, in this tutorial i explained how can we send key based encrypted parameter in an api request in the header instead of sending directly and modified the api as shown initially.&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>javascript</category>
      <category>api</category>
      <category>security</category>
    </item>
    <item>
      <title>Configure Authorization in OpenAPI(Swagger UI) for JWT in ASP.Net Core Web Api</title>
      <dc:creator>Ravi Ranjan Pandey</dc:creator>
      <pubDate>Mon, 05 Apr 2021 03:37:24 +0000</pubDate>
      <link>https://dev.to/raviranjanpandey/configure-authorization-in-openapi-swagger-ui-for-jwt-in-asp-net-core-web-api-1p1k</link>
      <guid>https://dev.to/raviranjanpandey/configure-authorization-in-openapi-swagger-ui-for-jwt-in-asp-net-core-web-api-1p1k</guid>
      <description>&lt;p&gt;OpenAPI Specifications are popular choices for REST Api documentation and Swagger UI is interactive API documentation in ASP.Net Webapi. &lt;/p&gt;

&lt;p&gt;Authorization needs to be configured for Swagger UI to bear Json Web Tokens(JWT) in the authorized APIs.&lt;/p&gt;

&lt;p&gt;Here's how you can add security schema in the dependency container.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
public void ConfigureServiceExtensions(IServiceCollection services, IConfiguration configuration)
        {
            services.AddSwaggerGen(c =&amp;gt;
            {
                c.SwaggerDoc("v1", new OpenApiInfo { Title = "MyProject", Version = "v1.0.0" });

                var securitySchema = new OpenApiSecurityScheme
                {
                    Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
                    Name = "Authorization",
                    In = ParameterLocation.Header,
                    Type = SecuritySchemeType.Http,
                    Scheme = "bearer",
                    Reference = new OpenApiReference
                    {
                        Type = ReferenceType.SecurityScheme,
                        Id = "Bearer"
                    }
                };

                c.AddSecurityDefinition("Bearer", securitySchema);

                var securityRequirement = new OpenApiSecurityRequirement
                {
                    { securitySchema, new[] { "Bearer" } }
                };

                c.AddSecurityRequirement(securityRequirement);

            });
        }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>csharp</category>
      <category>aspnetcore</category>
      <category>development</category>
    </item>
  </channel>
</rss>
