Encrypt Decrypt of a String in C# .NET

C# Encryption and Decryption of a String With a Simple Function Call

Cryptography is a big subject area and extremely important for modern software and programs. If you are writing any type of software you need an understanding of software security and methods to keep data, code and users secure. Encrypting data keeps it secure because it hides its meaning, converting the plaintext (or cleartext) to ciphertext. To see the data again you need to decrypt the ciphertext back to plaintext. A simple example is the encryption of passwords to protect them from use by others.

Encryption and decryption of a password or other strings containing data can be done in many ways. There are many character substitution or transposition methods that pre-date the computing era and can be traced back to classical times. Modern computer based methods use symmetric key and asymmetric key mathematical algorithms. There are lots of well established algorithms from which to choose. However not everyone wants to take a course in cryptography just to be able to encrypt a string to hide some data and decrypt it back again. That’s where this example C# encryption and decryption code comes in handy. This code was tested in Visual Studio 2013.

This C# code has been boiled down to an encryption function that takes a plaintext string and passphrase and returns an encrypted string. There is the reverse function that takes the ciphertext and the passphrase and returns the plaintext. This is a quick and easy method of adding some encryption to a C# project, or any .NET project. The encrypt decrypt C# string functions are in a simple class. An example project shows how simple it is to use them. Continue reading

List of IDEs for Android App Development, Which is Best for You?

Eclipse Alternatives for Android Application Development

An Integrated Development Environment (IDE) is an all-in-one solution that allows an application (app) developer (a.k.a. programmer) to perform the software development cycle repeatedly and quickly. That cycle is to design, write (or code), compile, test, debug and package the app software. For Android app development Google currently supports two IDEs (but read on for a list of alternative IDEs and languages):

  1. Android Developer Tools (ADT) – http://developer.android.com/sdk/index.html
  2. Android Studio – http://developer.android.com/sdk/installing/studio.html (in beta)

Both of these IDEs require the use of the Java computer language to write Apps. The first option uses the well established Eclipse IDE. The second option is based upon the IntelliJ IDE.

The Google IDEs and the Java language are not the only options for Android App development. Some developers might not need the power of Java or just don’t get on with C style languages. Some developers would like a single code base to support other platforms: Apple (iOS), Windows, Blackberry and the Web (HTML5). This is known as cross-platform development. Well there are plenty of alternatives to Google’s tools, see the following table for a list of Android app development IDE and computer language alternatives. Code can be written in different languages, like BASIC, HTML5 or Lua. Many of the alternatives are free to use, some open source, some restricted versions of paid for products. A few may not have a free version. Some will require the Android Software Development Kit (SDK) that comes with the Google tools to be installed. It is possible to install several IDEs onto the same computer to try them out.

List of Alternative Android App Development IDEs

Name Language C-P URL
AIDE (Android IDE) HTML5/C/C++ Yes http://www.android-ide.com/
Application Craft HTML5 Yes http://www.applicationcraft.com/
Basic4Android BASIC No http://www.basic4ppc.com/
Cordova HTML5 Yes https://cordova.apache.org/
Corona Lua Yes http://coronalabs.com/
Intel XDK HTML5 Yes https://software.intel.com/en-us/html5/tools
IntelliJIDEA Java No https://www.jetbrains.com/idea/features/android.html
Kivy Python Yes http://kivy.org/#home
MIT App Inventor Blocks Yes http://appinventor.mit.edu/explore/
Monkey X BASIC Yes http://www.monkeycoder.co.nz/
MonoGame C# Yes http://www.monogame.net/
MoSync HTML5/C/C++ Yes http://www.mosync.com/
NS BASIC BASIC Yes https://www.nsbasic.com/
PhoneGap HTML5 Yes http://phonegap.com/
RAD Studio XE Object Pascal, C++ Yes http://www.embarcadero.com/
RFO Basic BASIC No http://laughton.com/basic/
RhoMobile Suite Ruby Yes http://www.motorolasolutions.com/US-EN/Business+Product+and+Services/Software+and+Applications/RhoMobile+Suite
Telerik HTML5 Yes http://www.telerik.com/platform#overview
Titanium JavaScript Yes http://www.appcelerator.com/titanium/titanium-sdk/
Xamarin C# Yes http://xamarin.com/

Table Notes:

  1. C-P, Cross-Platform, if No only Android supported, if Yes supports App production for other platforms (you will need to check if your required platform is supported).
  2. Language, HTML5 also includes the related technologies of Cascading Style Sheets (CSS) and JavaScript.
  3. AIDE and RFO Basic allows code to be developed on the go on Android devices. The code can be packaged into full blown Apps.

Support for Android Programming

This above list of free and commercial IDEs for Android shows that other languages can be considered when wanting to develop apps. Some of these Android options provide cross platform development from the same app source code. (For some IDEs the Android SDK will need to be installed.) Purchased commercial Android development packages will come with varying degrees of support from the company and the user base. Open source and free packages will be supported by the user and development community, and sometimes paid for support is available. Forums are a useful source of answers for Android development issues.

Microsoft are developing Cordova support for Visual Studio, see Microsoft’s Multi-Device Hybrid Apps web page.

Android NDK

Google provides for free the Native Development Kit (NDK) that allows programming in C or C++, see the Android NDK page for more information. Use the NDK to optimise time critical portions of an App. Google does not recommend it for general App development.

Setting Up Google’s Android IDEs

If you need help installing Eclipse or Android Studio see our articles. For a quick Eclipse set up see:

For Android Studio set up see:

For a step-by-step set up of Eclipse see:

Please let us know of any other Android development options you come across. It would be interesting to hear of any App successes from using any of the above packages, drop us a line at dan@tekeye.biz.

Visual Studio Express Requirements – Operating System

Visual Studio Express is the Free Version of Microsoft’s IDE

When writing software for Microsoft Windows based systems there are many free programming tools available, including the free Windows development tools provided by Microsoft themselves. Visual Studio is the Integrated Development Environment (IDE) that Microsoft produces for programmers, a.k.a. developers, to write software for Windows. The free version of these development tools is called Visual Studio Express (VSE), the latest version is the 2013 release. The 2013 release coincides with the release of Windows 8.1 and replaces Visual Studio Express 2012.

The 2013 versions are aimed at users of the latest Windows operating systems, Windows 7, Windows 8, Windows 8.1, Windows Server 2008 and Windows Server 2012. For users still running Windows XP or Windows Vista (not including Starter Editions) then Visual Studio Express 2010 will be needed. There are several different versions of VSE 2013 for programmers, which target different uses. The Visual Studio Express requirements vary depending upon which version is used. The versions are for Web, Windows 8 Apps, Windows Desktop or Windows Phone. To move beyond those types of programs the Professional version and upwards of Visual Studio would be required, and these are paid for products. The Microsoft Visual Studio 2013 Express products can be accessed from this link.

Visual Studio Express 2013 System Requirements
Express 2013 Product Used To Develop Minimum Operating System Required for Installation
Express for Web Web sites and HTML5 applications Windows 7 SP1 (With IE 10)
Express for Windows Windows 8 Apps Windows 8.1
Express for Windows Desktop Windows Programs Windows 7 SP1 (With IE 10)
Express for Windows Phone Windows Phone Apps Windows 8

All current versions of VSE are available from this downloads page (scroll down to the Express products, just after the full product trial versions). There is also a version of Team Foundation Server (TFS), Microsoft’s source code and development management software. TFS Express is limited to 5 users (team members). VSE products require free registration to obtain a product key to use them beyond a 30 day trial period.

What is .NET?

Windows Developers Usually Use Microsoft .NET When Writing Programs

If you are new to writing software for Windows personal computers (PCs) it is not long before you come across Microsoft .NET (pronounced “dot net”). What is .NET? The simplest answer is to say that .NET is used to build and run programs on a computer. (For the complete beginner who knows nothing about computer programs read our article What is Computer Programming?) In this post we attempt to provide a brief explanation to .NET in they way of an introduction. Microsoft .NET is an important Windows technology to ease the development of computer programs.

.NET Provides a Framework to Help Write Complex Programs

Steel Building FrameworkWhenever you see a building, such as an office block or skyscraper, being constructed you will notice that a steel frame is used to provide the basic structure. On to this frame is fixed walls, windows, floors, ceilings and everything else that makes up a building. The framework is made of steel beams, rivets and welds. Everything that is attached to it is made from common building materials and components. It is the architects and builders that determine the final look of the building using standard components.

A similar thing occurs when computer programs are written, the software developer (a.k.a. computer programmer) decides the final functionality and look of a program but will use an existing set of components to help achieve the end requirement.

Microsoft .NET Libraries and Runtime Engine

Microsoft .NET is a computer framework that contains hundreds of useful components. The components are gathered together into libraries to organize them into categories. Libraries that contain components to draw on the screen, read input, talk to the Internet, etc. This allows the programmer to concentrate on producing the functionality of the software and not have to work on the code that controls the hardware. Modern software programs are written with a tool called an Integrated Development Environment (IDE). An IDE allows the programmer to write the code in an editor, run the code to test it and use a debugger to fix any errors found during testing. Many IDEs come with a set of common existing components to use, such as text boxes, buttons and image containers.

Visual Studio IDE

An Intergrated Development Environment

With the .NET framework and an IDE it only takes a few lines of code to get a simple program working. The speed of software development using .NET makes it a very useful framework for developers writing Windows programs. Continue reading

Running an Android SDK Sample App

How to Load and Run a Sample Program from the Android SDK

The Android Robot LogoThe Android Software Development Kit (SDK) gets updated with new version platforms for each new release of the Operating System (OS). Each version platform can be loaded onto your development machine with SDK Manager.exe. There are available sample Applications (Apps) to showcase Android features and provide example code that allows developers to see how to use the Android Application Programming Interface (API).

Getting Hold of the Android Samples

Each SDK platform version provides Android sample source code project, however, they must be selected for installation on your development machine using the SDK Manager program. Run SDK Manager and wait for it to finish doing it’s checks. Expand the required Android Version folder to see and select the Samples for SDK option.

Exmaple Apps can be Loaded with the SDK Manager

Once the samples have been installed they will be found in the android-sdk/samples folder in the Android SDK’s install directory. (On Windows this may be under the Local Settings/Application Data folder, e.g. C:\Documents and Settings\John Doe\Local Settings\Application Data\Android, or wherever you chose to install it.) There will be a folder for each Android API version for which you chose to install the samples, called android-x where x is the API version.

Android SDK Samples

See our article Use Android SDK Samples for Guidance to see a list, and brief description, of the example Apps supplied with the various Android versions. Continue reading

Change the Text Size in an Android Spinner

Why Using android:textSize on Spinner Does Not Work

The article Load Values into an Android Spinner showed how a Spinner is set up. It was stated in the article that the Spinner definition in the layout file does not define the View that the data being displayed uses. That is assigned when the Adapter that links the data to the Spinner is created. The previous article used the existing Android simple_spinner_item as the View for the data items. This means trying to change the size of the text being displayed with android:textSize or android:textAppearance attributes on the Spinner definition is a no go. This definition in a layout file will not show the text any bigger than default:

[code lang=”xml”]<Spinner android:id="@+id/contextChooser"

Maybe a Custom Layout?

One solution is to pass in a custom layout instead of using an Android default layout. For example create a new Android XML file in the res/layout folder called my_spinner.xml and add the code for a TextView (for tips on copy from the code boxes see Copying Code from the Articles):

[code lang=”xml”]<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"

Pass the new layout to the ArrayAdapter creation (the id has to be text1 for the Adapter to use the View):

[code lang=”Java”]ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.context_names, R.layout.my_spinner);[/code]

Bigger Text in an Android SpinnerThe text in the Spinner is now larger, but the default styling has been lost. This could be solved by assigning colors to the TextView, however, this would remove the Spinner styling from any theme that is being used on the device. Fortunately by using the Android feature that allows for the styling on Views to inherit from existing styles it is possible to get the Spinner back to the default theme but with the text size increase.

Extend the Default Theme

To achieve this first create a new XML file in the res/values folder, give it a name, here it is called my_style.xml, the name is not important as long as a file of the same name does not exist. In the file a style element is defined, here named MySpinnerLook. The style will inherit from an existing Android style. These can be viewed in the file styles.xml for the given platform, located in platforms/android-X/data/res/values where the android-sdk folder resides, with X being the API level of the platform being used. In styles.xml is found the Widget.TextView.SpinnerItem style. This is assigned to the parent attribute of the MySpinnerLook style (prefixing with @android:style/ or just @android:). The TextSize attribute is moved from the TextView layout file into this new style file. The my_style.xml file will have this code:

[code lang=”xml”]<?xml version="1.0" encoding="utf-8"?>
<style name="MySpinnerLook" parent="@android:TextAppearance.Widget.TextView.SpinnerItem">
<item name="android:textSize">22sp</item>

With the my_spinner.xml file no longer having the TextSize attribute the link to the new style file is with a style attribute pointing to MySpinnerLook like this:

[code lang=”xml”]<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"

In summary to change the text size for a Spinner either:

  • Create a custom TextView layout.
  • Change the text size with the android:textSize attribute.
  • Change the text color with android:textColor.


  • Create a custom style.
  • Use android:TextAppearance.Widget.TextView.SpinnerItem as the parent style.
  • Change the text size with the android:textSize attribute.

An Android Spinner with Bigger Text

Hello Holo

When Google released Android 3.0 (API Level 11) it heralded change of default theme, the new Holo theme was introduced. In Holo the Spinner style is Holo.Widget.TextView.SpinnerItem. However in our example above we are saying that the parent is Widget.TextView.SpinnerItem. The link to our new style has been broken, but not for long. For devices running API 11 or later we can create a res/values-v11 folder, copy my_style.xml into this folder then change the parent attribute to point to the new Holo theme:

[code lang=”xml”]<?xml version="1.0" encoding="utf-8"?>
<style name="MySpinnerLook" parent="@android:TextAppearance.Holo.Widget.TextView.SpinnerItem">
<item name="android:textSize">22sp</item>

Load Values into an Android Spinner

Android Spinner DemoThis article takes a look at adding string items to the Android Spinner. The Spinner View is useful when you want the user to pick an item from a predetermined list but do not want to take up a lot of screen space, for example by using several radio buttons. Programmers moving to Android from other environments will notice a difference in terminology. The Android Spinner behaves in a similar fashion to what some may call a drop down list, whilst a spinner on other platforms is closer to the Android NumberPicker as seen when setting an alarm on an Android device. The NumberPicker is not directly available to use from the SDK, although open source versions are available, see https://github.com/mrn/numberpicker.

Programmers coding with the Android SDK soon come across a familiar pattern when designing the user interface. There are Views that go on the screens, the data that needs to be displayed in those Views and the code that links the two together. For some Views and types of data the code that links them together is provided by an Adapter. In this example the data is an array of strings, the View is obviously the Spinner, and an ArrayAdapter is the link. The array of strings is defined in a values file in the res/values folder. The Spinner is added to a layout file in the res/layout folder. Both could be done in code but it is recommended for ease of maintenance that strings and layouts be defined separately. The following tutorial adds a Spinner to a screen in a new Eclipse project. Continue reading

About Box for an Android App

How to Build a Reusable About Dialog for Your Android Apps

The venerable About Box, whatever the Operating System, whatever the program the chances are it has an About option. There is a Wikipedia entry for it, http://en.wikipedia.org/wiki/About_box, and it is useful for support:

Hello, there is a problem with my application?

Hi, can you press About and tell me the version number?

Since it is likely to be required again and again it is worth having a ready made About Box class that can be easily added to any new App that is developed. As a minimum the About should display a dialog with a title, e.g. About My App, the Version Name from the manifest, some descriptive text (loaded from a string resource) and an OK button. This tutorial presents the code for an About Box class that can be dropped straight into any App.

The Version Name can be read from the PackageInfo class. (PackageInfo is obtained from PackageManager which itself is available from the App’s Context). Here is a method to read an App’s Version Name string.

[code lang=”Java”]static String VersionName(Context context) {
try {
return context.getPackageManager().getPackageInfo(context.getPackageName(),0).versionName;
} catch (NameNotFoundException e) {
return "Unknown";

Continue reading