Monday, April 25, 2016

SHA512 Hash in C#

Computing SHA 512 is easy for dotnet developers. in your application add System.Security.Cryptography, and then use below method for encryption of string which can be plain text.

APISecretKey is privateKey for encryption, which can be empty as well.
EncryptionType parameter shows which type of return value is needed, either in hex format or base64 string.

MSDN reference  is HERE 

Friday, April 22, 2016

How to calculate BMI in HTML and Javascript

as per the formula, we can calculate the bmi with height and weight, if you are creating a simple html page then here is the code to use.


 function calculateBMI() {
            var age = parseInt(document.getElementById("txtage").value);
            if (isNaN(age) || age <= 0) {
                alert("Provide valid Age");
            var weigth = parseInt(document.getElementById("txtweigth").value);
            if (isNaN(weigth) || weigth <= 0) {
                alert("Provide valid weight");
            var height = parseInt(document.getElementById("txtheight").value);
            if (isNaN(height) || height <= 0) {
                alert("Provide valid height");
            var heightPercentage = 1;
            if (height > 10)
                heightPercentage = height / 100;

            var BMI = weigth / (heightPercentage * heightPercentage);
            BMI = BMI.toFixed(2);
            document.getElementById("lblBMI").innerText = "Your BMI is  " + BMI;
            if (BMI > 25)
                document.getElementById("lblBMI").className = "redBMI";
            else if (BMI > 18.5)
                document.getElementById("lblBMI").className = "greenBMI";
                document.getElementById("lblBMI").className = "yellowBMI";
CSS Style 

<style type="text/css">
        .greenBMI {
            color: green;
            font-weight: bold;

        .redBMI {
            color: red;
            font-weight: bold;

        .yellowBMI {
            font-weight: bold;


 Enter the Age : <input id="txtage" type="number" name="age" min="5" max="99" maxlength="2" required />
    <br />
    <br />
    Enter weigth  : <input id="txtweigth" type="number" name="weigth" min="5" max="200" maxlength="5" /> in Kg
    <br />
    <br />
    Enter height :  <input id="txtheight" type="number" name="height" min="5" max="200" maxlength="5" /> in cm
    <br />
    <br />
    <input type="button" onclick="calculateBMI()" value="Calculate BMI">
    <br />
    <span id="lblBMI"></span>

Thursday, April 21, 2016

WCF REST Service Error "Request Entity too large"

Recently I had this issue in my WCF service, this service was for file upload and download.

in uploading the file, WCF was throwing an error of Request entity too large. later after some searching on net, I have found to change the web.config for webhttpBinding, like below.


maxBufferSize="2147483647" transferMode="Streamed">

which worked fine for me.