Few day ago I needed a JavaScript AES implementation (the Rijndael advanced encryption algorithm) which I can test instantly in my Web browser (two fields “text” and “password” and “encrypt” button). I searched for “online AES tool” but found nothing that is ready-to-use so I needed to write one. For those who need instant online Browser-based JavaScript AES encryptor / decryptor that runs without any plugins client-side, enjoy! Thanks to Mark Percival for his AES JavaScript library.
How the JavaScript AES Encryptor / Decryptor Works?
This online form encrypts with AES (Rijndael) instantly given text with the AES-128 algorithm and produces a BASE64-encoded output: cipher = BASE64_Encode(AES_Encrypt(text, password)). The algorithm first extracts a 128-bit secret key and AES IV (initial vector) from the password and then after padding the input encrypts it (by 128-bit blocks). Finally the encrypted binary result is encoded in BASE64. A random salt is injected along with the password to strengthen the encryption code. The key-extraction algorithm and the format of the output AES-encrypted message is compatible with OpenSSL.
The decryption algorithm first decodes the BASE64 string, extracts from it the random salt used during the encryption, extracts the AES key and IV from the password and the salt and decrypts back the encrypted text.
The encryption / decryption implementation of the AES (Advanced Encryption Standard, a.k.a. Rijndael) algorithm in JavaScript is written by Mark Percival (see his open-source project gibberish-aes at GitHub).
AES Online Encryption Tool – Source Code
Below is the source code of the online AES encryption tool:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="https://raw.github.com/mdp/gibberish-aes/master/src/gibberish-aes.js"></script>
<title>Free Online AES Tool - Encrypt / Decrypt Text with AES Online</title>
</head>
<body>
<h1>Online AES Encryptor / Decryptor - Free AES Tool</h1>
<h2>(JavaScript client-side AES cipher implementation)</h2>
<table>
<tr>
<td>Text to encrypt:</td>
<td><textarea id="text" />Enter the text to be encrypted here...</textarea></td>
</tr>
<tr>
<td>Password:</td>
<td><input id="password" value="some password" /></td>
</tr>
<tr>
<td>Encrypted text:</td>
<td><textarea id="encryptedText" readonly="readonly"></textarea></td>
</tr>
<tr>
<td>Decrypted text:</td>
<td><textarea id="decryptedText" readonly="readonly"></textarea></td>
</tr>
<tr>
<td colspan="2" align="center">
<button id="buttonStart">AES Encrypt / Decrypt</button>
</td>
</tr>
</table>
<script>
$('#buttonStart').click(function() {
var text = $('#text').val();
var pass = $('#password').val();
GibberishAES.size(128);
var encrypted = GibberishAES.enc(text, pass);
$('#encryptedText').val(encrypted);
var decrypted = GibberishAES.dec(encrypted, pass);
$('#decryptedText').val(decrypted);
});
</script>
</body>
</html>
Recently I was again asked how do we perform “cin >> a >> b” in C# or how we can enter a sequence of numbers from the console in C#. In C++ we have very powerful class called “cin” (more correctly std::cin located in the standard library “iosteam”) that overloads the >> operator and allows entering anything from the standard input (stdin): numbers, characters, strings and other data types.
I searched for “cin in C#” and found nothing similar to “std::cin” for C#, so I needed to write such a class.
The Nakov.IO.Cin Class – “cin” Functionality for C# / .NET
Initially I had an idea to implement my C# “cin” class exactly like in C++. Unfortunately this was impossible because the C# language has certain limitations:
You cannot override the >> operator in C# for any type except int
You cannot override the >> operator in C# for output / by-ref types (e.g. out int, ref int)
You cannot add extension methods to the Console class because it is static (so additions like Console.Cin, Console.NextInt(), Console.In << x << b and Console.Cin.NextInt() cannot be added to it)
Finally I decided to implement my C# console simplifies reader it in a way similar to the Java syntax used in the java.util.Scanner class. See the code below:
namespace Nakov.IO
{
using System;
using System.Text;
using System.Globalization;
/// <summary>
/// Console input helper for C# and .NET. Allows simplified reading of numbers and string
/// tokens from the console in a way similar to "cin" in C++ and java.util.Scanner in Java.
/// </summary>
///
/// <copyright>
/// (c) Svetlin Nakov, 2011 - http://www.nakov.com
/// </copyright>
///
/// <example>
/// // In C++ we will use "cin >> x >> y;"
/// // Using Nakov.IO.Cin we can do the same as follows:
/// int x = Cin.NextInt();
/// double y = Cin.NextDouble();
/// </example>
///
public static class Cin
{
/// <summary>
/// Reads a string token from the console
/// skipping any leading and trailing whitespace.
/// </summary>
public static string NextToken()
{
StringBuilder tokenChars = new StringBuilder();
bool tokenFinished = false;
bool skipWhiteSpaceMode = true;
while (!tokenFinished)
{
int nextChar = Console.Read();
if (nextChar == -1)
{
// End of stream reached
tokenFinished = true;
}
else
{
char ch = (char)nextChar;
if (char.IsWhiteSpace(ch))
{
// Whitespace reached (' ', '\r', '\n', '\t') -->
// skip it if it is a leading whitespace
// or stop reading anymore if it is trailing
if (!skipWhiteSpaceMode)
{
tokenFinished = true;
if (ch == '\r' && (Environment.NewLine == "\r\n"))
{
// Reached '\r' in Windows --> skip the next '\n'
Console.Read();
}
}
}
else
{
// Character reached --> append it to the output
skipWhiteSpaceMode = false;
tokenChars.Append(ch);
}
}
}
string token = tokenChars.ToString();
return token;
}
/// <summary>
/// Reads an integer number from the console
/// skipping any leading and trailing whitespace.
/// </summary>
public static int NextInt()
{
string token = Cin.NextToken();
return int.Parse(token);
}
/// <summary>
/// Reads a floating-point number from the console
/// skipping any leading and trailing whitespace.
/// </summary>
/// <param name="acceptAnyDecimalSeparator">
/// Specifies whether to accept any decimal separator
/// ("." and ",") or the system's default separator only.
/// </param>
public static double NextDouble(bool acceptAnyDecimalSeparator = true)
{
string token = Cin.NextToken();
if (acceptAnyDecimalSeparator)
{
token = token.Replace(',', '.');
double result = double.Parse(token, CultureInfo.InvariantCulture);
return result;
}
else
{
double result = double.Parse(token);
return result;
}
}
/// <summary>
/// Reads a decimal number from the console
/// skipping any leading and trailing whitespace.
/// </summary>
/// <param name="acceptAnyDecimalSeparator">
/// Specifies whether to accept any decimal separator
/// ("." and ",") or the system's default separator only.
/// </param>
public static decimal NextDecimal(bool acceptAnyDecimalSeparator = true)
{
string token = Cin.NextToken();
if (acceptAnyDecimalSeparator)
{
token = token.Replace(',', '.');
decimal result = decimal.Parse(token, CultureInfo.InvariantCulture);
return result;
}
else
{
decimal result = decimal.Parse(token);
return result;
}
}
}
}
How Cin.NextDouble() Works?
My class Nakov.IO.Cin allows simplified entering string tokens, integer numbers, floating-point numbers and decimal numbers in C# from the standard input (the console). When reading a sequence of numbers, we can separate them with a single space, multiple spaces, new line separators or any other sequence of whitespace characters: spaces, tabs, new lines (\n, \r\n), etc.
In addition Nakov.IO.Cin solves the culture-specific problem with the decimal point separator which may be “,” in some countries (like Bulgaria) and “.” in other countries (like USA and Canada). The Cin.NextDouble() and Cin.NextDecimal() methods accept a Boolean parameter which specifies whether the numbers should be parsed using the default decimal separator (specified in the regional settings in Windows) or by accepting both separators: “.” and “,”. By default both decimal separators are accepted when entering numbers by Nakov.IO.Cin.NextDouble() and Nakov.IO.Cin.NextDecimal().
Using the Nakov.IO.Cin Class – Example
In the below example I show how to use the class “Nakov.IO.Cin” to enter integer numbers, floating-point numbers, decimal numbers and string tokens:
using System;
using Nakov.IO; // see http://www.nakov.com/tags/cin
public class CinExample
{
static void Main()
{
Console.Write("Enter your name: ");
string name = Console.ReadLine();
Console.Write("Enter two integers x and y separated by whitespace: ");
// cin >> x >> y;
int x = Cin.NextInt();
double y = Cin.NextDouble();
Console.Write("Enter your age: ");
int age = int.Parse(Console.ReadLine());
Console.WriteLine("Name: {0}, Age: {1}", name, age);
Console.WriteLine("x={0}, y={1}", x, y);
Console.Write("Enter a positive integer number N: ");
int n = Cin.NextInt();
Console.Write("Enter N decimal numbers separated by a space: ");
decimal[] numbers = new decimal[n];
for (int i = 0; i < n; i++)
{
numbers[i] = Cin.NextDecimal();
}
Console.Write("The numbers in ascending order: ");
Array.Sort(numbers);
for (int i = 0; i < n; i++)
{
Console.Write(numbers[i]);
Console.Write(' ');
}
Console.WriteLine();
Console.WriteLine("Enter two strings seperated by a space: ");
string firstStr = Cin.NextToken();
string secondStr = Cin.NextToken();
Console.WriteLine("First str={0}", firstStr);
Console.WriteLine("Second str={0}", secondStr);
}
}
Translating from C++ “cin” to C# Using the C# “cin” Class
Once you have included the class Nakov.IO.Cin to your C# / VB.NET project, you could translate the following C++ program into C#:
Sample C++ code entering a number N and a sequence of N integer numbers, separated by a space (or any other sequence of whitespace characters):
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int* numbers = new int[n];
for (int i = 0; i < n; i++)
{
cin >> numbers[i];
}
for (int i = 0; i < n; i++)
{
cout << numbers[i] << ' ';
}
}
The same code written in C# using the C# “cin” class (Nakov.IO.Cin) is as follows:
using System;
using Nakov.IO; // see http://www.nakov.com/tags/cin
public class EnteringNumbers
{
static void Main()
{
int n;
n = Cin.NextInt();
int[] numbers = new int[n];
for (int i = 0; i < n; i++)
{
numbers[i] = Cin.NextInt();
}
for (int i = 0; i < n; i++)
{
Console.Write(numbers[i] + " ");
}
}
}
With both the programs (the C++ and the C# one) you are free to enter all the requested numbers on a single line (e.g. “3 1 –2 3”) or on separate lines (e.g. “\r\n 3 \r\n 1 \t –2 \r\n\r\n 3”)) and they will be parsed correctly, as expected.
For the entire Scrum community in Bulgaria I am happy to announce that Telerik Academy will host a seminar on agile development with the Scrum, Kanban and Lean methodologies on 20 October 2011 in Sofia.
Seminar Topic and Annotation
Come talk Scrum with the Scrum Guys: Kanban, Scrum / Agile Q&A
In this session Joel Semeniuk (Executive VP) and Stephen Forte (Chief Strategy Officer) of Telerik will talk about Agile yesterday, today, and tomorrow. Their talk will briefly reflect on the 10 since the signing of the Agile Manifesto, discuss the significance of Scrum as well as emerging influencers such as Lean and Kanban in the evolution of Agile as we know it. This session will then upon up to a full Questions and Answers where Steve and Joel will discuss anything of interest to the audience.
As usually, the event is free and is open to anyone interested in the discussed topics. We have capacity of 120 seats in out new training lab.
Speakers
Stephen Forte and Joel Semeniuk are well known top speakers from the most influential world’s software development conferences.
Stephen Forte is the Chief Strategy Officer of Telerik, a leading vendor in .NET components. Prior he was the CTO and co-founder of Corzen Inc., a New York based provider of online market research data for Wall Street Firms. Corzen was acquired by Wanted Technologies (TXV: WAN) in 2007. Stephen is also the Microsoft Regional Director for the NY Metro region and speaks regularly at industry conferences around the world. He has written several books on application and database development including Programming SQL Server 2008 (MS Press). Prior to Corzen, Stephen served as the CTO of Zagat Survey in New York City and also was co-founder and CTO of the New York based software consulting firm The Aurora Development Group. He currently an MVP, INETA speaker and is the co-moderator and founder of the NYC .NET Developer User Group. Stephen has an MBA from the City University of New York.
Joel Semeniuk is a founder of Imaginet Resources Corp., a Canadian based Microsoft Gold Partner. Currently, Joel is also serving as an Executive VP at Telerik in charge of the Team Productivity Division. He is also a Microsoft Regional Director and MVP Microsoft ALM and has a degree in Computer Science. With over 18 years of experience, Joel specializes in helping organizations around the world realize their potential through maturing their software development and information technology practices. Joel is passionate about Application Lifecycle Management tooling, techniques, and mindsets and regularly speaks at conferences around the world on a wide range of ALM topics. Joel is also the co-author of “Managing Projects with Microsoft Visual Studio Team System” published by Microsoft Press as well as dozens of other articles for popular trade magazines.
As experienced software engineer, team leader of software development projects and trainer of skillful IT professionals I often conduct job interviews and prepare people for passing a software development / computer programming job interviews. Instead explaining everyone separately the concepts how to pass software engineering interview I wrote a presentation (in English) and recorded a video (in Bulgarian) explaining the fundamentals of interview passing in a software development company.
How to Pass an Interview for Software Engineering Job – Presentation and Guidelines by Svetlin Nakov
Modern Web applications need to have a way to inform the user about the result of their actions. For example if someone press the “Save” button, he or she should be notified with a message like “Document saved” or error message “Cannot save the document”. In addition some of the notifications are not too important and should be shown for a while and disappear automatically after few seconds.
To address this problem I recently designed a reusable ASP.NET user control (.ascx) which displays a list of messages in ASP.NET Web Forms application (like a MessageBox in desktop applications):
ErrorSuccessNotifier Web User Control
The Web user control “ErrorSuccessNotifier.ascx” consists of:
API for adding notification messages which will be displayed the first time when the control is rendered:
It supports 4 types of messages: Info, Success, Warning and Error messages.
A static method to add a notification message which consists of text, type and auto-hide settings
Images (for the icons)
CSS styles (dynamically included on demand)
JavaScript code (dynamically included on demand)
Ideally, the ErrorSuccessNotifier should be inserted in the master page (Site.master) of the ASP.NET Web Forms application and will display error and notification messages in all pages of the application (when such messages are assigned during the event handling C# logic).
Few days ago I gave a talk about software architectures. My goal was to explain as easy as possible the main ideas behind the most popular software architectures like the client-server model, the 3-tier and multi-tier layered models, the idea behind SOA architecture and cloud computing, and few widely used architectural patterns like MVC (Model-View-Controller), MVP (Model-View-Presenter), PAC (Presentation Abstraction Control), MVVM (Model-View-ViewModel). In my talk I explain that MVC, MVP and MVVM are not necessary bound to any particular architectural model like client-server, 3-tier of SOA. MVC, MVP and MVVM are architectural principles applicable when we need to separate the presentation (UI), the data model and the presentation logic.
Additionally I made an overview of the popular architectural principals IoC (Inversion of Control) and DI (Dependency Injection) and give examples how to build your own Inversion of Control (IoC) container.
My overview of the software architectures, patterns and principles was from the .NET development perspective but the content of my presentation can serve as a general reference about “software architectures”.
I was unable to find comprehensive and still compact overview of all mentioned topics about software architecture and architectural design patterns so I hope everyone will enjoy my presentation and the way I explain all these concepts:
Telerik organized the first front-end development conference in Bulgaria – Front-End Day 2011. It was held in Sofia, in April 26-27. Our guests were Peter-Paul Koch (PPK) and few other Web, front-end and mobile Web development gurus.
It was a nice event, focusing on the modern Web front-end technologies. The second day was hosted in Telerik Academy where we had a free training on Web game development and mobile Web.