Sunday, 26 March 2017

secure electronic transaction

SECURE ELECTRONIC TRANSACTION SET is an open encryption and security specification designed to protect credit card transactions on the Internet. The current version, SETv1, emerged from a call for security standards by MasterCard and Visa in February 1996. A wide range of companies were involved in developing the initial specification, including IBM, Microsoft, Netscape, RSA, Terisa, and Verisign. Beginning in 1996. SET is not itself a payment system. Rather it is a set of security protocols and formats that enables users to employ the existing credit card payment infrastructure on an open network, such as the Internet, in a secure fashion. In essence, SET provides three services:
 • Provides a secure communications channel among all parties involved in a transaction
 • Provides trust by the use of X.509v3 digital certificates
 • Ensures privacy because the information is only available to parties in a transaction when and
where necessary.
 SET Overview: A good way to begin our discussion of SET is to look at the business requirements for SET, its key features, and the participants in SET transactions.
Requirements: The SET specification lists the following business requirements for secure payment processing with credit cards over the Internet and other networks:
• Provide confidentiality of payment and ordering information: It is necessary to assure cardholders that this information is safe and accessible only to the intended recipient. Confidentiality also reduces the risk of fraud by either party to the transaction or by malicious third parties. SET uses encryption to provide confidentiality.
• Ensure the integrity of all transmitted data: That is, ensure that no changes in content occur during transmission of SET messages. Digital signatures are used to provide integrity.
• Provide authentication that a cardholder is a legitimate user of a credit card account: A mechanism that links a cardholder to a specific account number reduces the incidence of fraud and the overall cost of payment processing. Digital signatures and certificates are used to verify that a cardholder is a legitimate user of a valid account.
 • Provide authentication that a merchant can accept credit card transactions through its relationship with a financial institution: This is the complement to the preceding requirement. Cardholders need to be able to identify merchants with whom they can conduct secure transactions. Again, digital signatures and certificates are used.
 • Ensure the use of the best security practices and system design techniques to protect all legitimate parties in an electronic commerce transaction: SET is a well-tested specification based on highly secure cryptographic algorithms and protocols.
 • Create a protocol that neither depends on transport security mechanisms nor prevents their use: SET can securely operate over a "raw" TCP/IP stack. However, SET does not interfere with the use of other security mechanisms, such as IPSec and SSL/TLS.
 • Facilitate and encourage interoperability among software and network providers: The SET protocols and formats are independent of hardware platform, operating system, and Web software. Key Features of SET To meet the requirements just outlined, SET incorporates the following features:
 • Confidentiality of information: Cardholder account and payment information is secured as it travels across the network. An interesting and important feature of SET is that it prevents the merchant from learning the cardholder's credit card number; this is only provided to the issuing bank. Conventional encryption by DES is used to
provide confidentiality.
• Integrity of data: Payment information sent from cardholders to merchants includes order information, personal data, and payment instructions. SET guarantees that these message contents are not altered in transit. RSA digital signatures, using SHA-1 hash codes, provide message integrity. Certain messages are also protected by HMAC using SHA-1.
• Cardholder account authentication: SET enables merchants to verify that a cardholder is a legitimate user of a valid card account number. SET uses X.509v3 digital certificates with RSA signatures for this purpose.
 • Merchant authentication: SET enables cardholders to verify that a merchant has a relationship with a financial institution allowing it to accept payment cards. SET uses X.509v3 digital certificates with RSA signatures for this purpose. Note that unlike IPSec and SSL/TLS, SET provides only one choice for each cryptographic algorithm. This makes sense, because SET is a single application with a single set of requirements, whereas IPSec and SSL/TLS are intended to support a range of applications.

Wednesday, 22 March 2017

Jagged array

Jagged Array
A jagged array is an array whose elements are arrays. The elements of a jagged array can be of different dimensions and sizes. A jagged array is sometimes called an "array of arrays." The following examples show how to declare, initialize, and access jagged arrays.
The following is a declaration of a single-dimensional array that has three elements, each of which is a single-dimensional array of integers:
C#
int[][] jaggedArray = new int[3][];
Before you can use jaggedArray, its elements must be initialized. You can initialize the elements like this:
C#
jaggedArray[0] = new int[5];
jaggedArray[1] = new int[4];
jaggedArray[2] = new int[2];
Each of the elements is a single-dimensional array of integers. The first element is an array of 5 integers, the second is an array of 4 integers, and the third is an array of 2 integers.
It is also possible to use initializers to fill the array elements with values, in which case you do not need the array size. For example:
C#
jaggedArray[0] = new int[] { 1, 3, 5, 7, 9 };
jaggedArray[1] = new int[] { 0, 2, 4, 6 };
jaggedArray[2] = new int[] { 11, 22 };
You can also initialize the array upon declaration like this:
C#
    int[][] jaggedArray2 = new int[][]
{
    new int[] {1,3,5,7,9},
    new int[] {0,2,4,6},
    new int[] {11,22}
};
You can use the following shorthand form. Notice that you cannot omit the new operator from the elements initialization because there is no default initialization for the elements:
C#
    int[][] jaggedArray3 =
{
    new int[] {1,3,5,7,9},
    new int[] {0,2,4,6},
    new int[] {11,22}
};
A jagged array is an array of arrays, and therefore its elements are reference types and are initialized to null.
You can access individual array elements like these examples:
C#
// Assign 77 to the second element ([1]) of the first array ([0]):
jaggedArray3[0][1] = 77;

// Assign 88 to the second element ([1]) of the third array ([2]):
jaggedArray3[2][1] = 88;
It is possible to mix jagged and multidimensional arrays. The following is a declaration and initialization of a single-dimensional jagged array that contains three two-dimensional array elements of different sizes. For more information about two-dimensional arrays, see Multidimensional Arrays (C# Programming Guide).
C#
int[][,] jaggedArray4 = new int[3][,]
{
    new int[,] { {1,3}, {5,7} },
    new int[,] { {0,2}, {4,6}, {8,10} },
    new int[,] { {11,22}, {99,88}, {0,9} }
};


Enumeration in C#

ENUMERATIONS
An enumeration is a special kind of value type limited to a restricted and unchangeable set of numerical values. By default, these numerical values are integers, but they can also be longs, bytes, etc. (any numerical value except char) as will be illustrated below.
When you define an enumeration you provide literals which are then used as constants for their corresponding values. The following code shows an example of such a definition:
1.
public enum DAYS
2.
{
3.
Monday,
4.
Tuesday,
5.
Wednesday,
6.
Thursday,
7.
Friday,
8.
Saturday,
9.
Sunday
10.
}



Note, however, that there are no numerical values specified in the above. Instead, the numerical values are (we think) set up according to the following two rules:
1. For the first literal: if it is unassigned, set its value to 0.
2. For any other literal: if it is unassigned, then set its value to one greater than the value of the preceding literal.
From these two rules, it can be seen that DAYS.Monday will be set to 0, and the values increased until DAYS.Sunday is set to 6. Note also how we are referring to these values - the values specified in an enumeration are static, so we have to refer to them in code using the name of the enumeration: "DAYS.Monday" rather than just "Monday". Furthermore, these values are final - you can't change their runtime value.
The following code demonstrates how you can override the default setting which makes the default values integers. In this example, the enumeration values are set to bytes.
1.
enum byteEnum : byte
2.
{
3.
A,
4.
B
5.
}



You can also override the default numerical values of any and all of the enumeration elements. In the following example, the first literal is set to value 1. The other literals are then set up according to the second rule given above, so DAYS.Sunday will end up equal to 7.
1.
public enum DAYS
2.
{
3.
Monday=1,
4.
Tuesday,
5.
Wednesday,
6.
Thursday,
7.
Friday,
8.
Saturday,
9.
Sunday
10.
}



In the two examples given, the values of each literal has been unique within the enumeration. This is usually how you will want things to be, but in fact the values need not be unique. In the following case, the value of DAYS.Thursday is also set to equal 1. The values assigned to the other literals will follow the rules given previously, so both DAYS.Tuesday and DAYS.Friday will equal 2, etc.
1.
public enum DAYS
2.
{
3.
Monday=1,
4.
Tuesday,
5.
Wednesday,
6.
Thursday=1,
7.
Friday,
8.
Saturday,
9.
Sunday
10.
}



Strings in C#

Strings
In C#, you can use strings as array of characters, However, more common practice is to use the string keyword to declare a string variable. The string keyword is an alias for the System.String class.

Creating a String Object

You can create string object using one of the following methods:
· By assigning a string literal to a String variable
· By using a String class constructor
· By using the string concatenation operator (+)
· By retrieving a property or calling a method that returns a string
· By calling a formatting method to convert a value or an object to its string representation
The following example demonstrates this:
using System;
namespace StringApplication
{
   class Program
   {
      static void Main(string[] args)
      {
         //from string literal and string concatenation
         string fname, lname;
         fname = "Rowan";
         lname = "Atkinson";
         
         string fullname = fname + lname;
         Console.WriteLine("Full Name: {0}", fullname);
         
         //by using string constructor
         char[] letters = { 'H', 'e', 'l', 'l','o' };
         string greetings = new string(letters);
         Console.WriteLine("Greetings: {0}", greetings);
         
         //methods returning string
         string[] sarray = { "Hello", "From", "Tutorials", "Point" };
         string message = String.Join(" ", sarray);
         Console.WriteLine("Message: {0}", message);
         
         //formatting method to convert a value
         DateTime waiting = new DateTime(2012, 10, 10, 17, 58, 1);
         string chat = String.Format("Message sent at {0:t} on {0:D}", waiting);
         Console.WriteLine("Message: {0}", chat);
      }
   }
}
When the above code is compiled and executed, it produces the following result:
Full Name: Rowan Atkinson
Greetings: Hello
Message: Hello From Tutorials Point
Message: Message sent at 5:58 PM on Wednesday, October 10, 2012

String Builder Class
A StringBuilder object is not a string but rather an auxiliary object used for manipulating characters. It contains a buffer, typically initialized with a string but usually larger than that string. This buffer can be manipulated in place without creating a new string: You can insert, append, remove, and replace characters. When you're done manipulating the characters, use StringBuilder's ToString method to extract the finished string from it. 

Both String and StringBuilder contain Unicode characters of type Char and support an indexer that returns Char. Because the String class is immutable, its indexer is read-only, but the StringBuilder indexer is readable/writeable. Listing 20.38 illustrates how to manipulate characters with the StringBuilder class and then place the characters into a String object. 

Listing 20.38: StringBuilder Class Manipulation 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StringBuilderClass
{
    class Program
    {
        static void Main(string[] args)
        {
            String MyName;
            StringBuilder MyOtherName = new StringBuilder("Hello");
            MyOtherName.Remove(2, 3); // produces "He"
            MyOtherName.Insert(2, "lp"); // produces "Help"
            MyOtherName.Replace('l', 'a'); // produces "Heap"
            MyName = MyOtherName.ToString();
        }
    }
}

You can use either String or StringBuilder for string operations. Deciding which to use depends on the frequency of the string modification. If you modify the string frequently-in operations like reassigning, appending, removing, and replacing some characters-you should choose the StringBuilder class. However, if your methods do not change the string value much, registering the String class to the .NET Framework's internal string table will save space in memory for duplicate strings. The framework also provides you faster access to string literal values stored in variables. The .NET Framework automatically handles these operations behind the scenes for you. 

Arrays in C#

The Array Type


Another data type is the Array, which can be thought of as a container that has a list of storage locations for a specified type. When declaring an Array, specify the type, name, dimensions, and size.
An array stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type stored at contiguous memory locations.
Instead of declaring individual variables, such as number0, number1, ..., and number99, you declare one array variable such as numbers and use numbers[0], numbers[1], and ..., numbers[99] to represent individual variables. A specific element in an array is accessed by an index.
All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element.

Declaring Arrays

To declare an array in C#, you can use the following syntax:
datatype[] arrayName;
where,
· datatype is used to specify the type of elements in the array.
· [ ] specifies the rank of the array. The rank specifies the size of the array.
· arrayName specifies the name of the array.
For example,
double[] balance;

Initializing an Array

Declaring an array does not initialize the array in the memory. When the array variable is initialized, you can assign values to the array.
Array is a reference type, so you need to use the new keyword to create an instance of the array. For example,
double[] balance = new double[10];

Assigning Values to an Array

You can assign values to individual array elements, by using the index number, like:
double[] balance = new double[10];
balance[0] = 4500.0;
You can assign values to the array at the time of declaration, as shown:
double[] balance = { 2340.0, 4523.69, 3421.0};
You can also create and initialize an array, as shown:
int [] marks = new int[5]  { 99,  98, 92, 97, 95};
You may also omit the size of the array, as shown:
int [] marks = new int[]  { 99,  98, 92, 97, 95};
You can copy an array variable into another target array variable. In such case, both the target and source point to the same memory location:
int [] marks = new int[]  { 99,  98, 92, 97, 95};
int[] score = marks;
When you create an array, C# compiler implicitly initializes each array element to a default value depending on the array type. For example, for an int array all elements are initialized to 0.

Accessing Array Elements

An element is accessed by indexing the array name. This is done by placing the index of the element within square brackets after the name of the array. For example,
double salary = balance[9];

ArrayList
It represents an ordered collection of an object that can be indexed individually. It is basically an alternative to an array. However, unlike array you can add and remove items from a list at a specified position using an index and the array resizes itself automatically. It also allows dynamic memory allocation, adding, searching and sorting items in the list.

Methods and Properties of ArrayList Class

The following table lists some of the commonly used properties of the ArrayList class:
Property
Description
Capacity
Gets or sets the number of elements that the ArrayList can contain.
Count
Gets the number of elements actually contained in the ArrayList.
IsFixedSize
Gets a value indicating whether the ArrayList has a fixed size.
IsReadOnly
Gets a value indicating whether the ArrayList is read-only.
Item
Gets or sets the element at the specified index.
The following table lists some of the commonly used methods of the ArrayList class:
Sr.No.
Methods
1
public virtual int Add(object value); 
Adds an object to the end of the ArrayList.
2
public virtual void AddRange(ICollection c); 
Adds the elements of an ICollection to the end of the ArrayList.
3
public virtual void Clear(); 
Removes all elements from the ArrayList.
4
public virtual bool Contains(object item); 
Determines whether an element is in the ArrayList.
5
public virtual ArrayList GetRange(int index, int count); 
Returns an ArrayList which represents a subset of the elements in the source ArrayList.
6
public virtual int IndexOf(object); 
Returns the zero-based index of the first occurrence of a value in the ArrayList or in a portion of it.
7
public virtual void Insert(int index, object value); 
Inserts an element into the ArrayList at the specified index.
8
public virtual void InsertRange(int index, ICollection c); 
Inserts the elements of a collection into the ArrayList at the specified index.
9
public virtual void Remove(object obj); 
Removes the first occurrence of a specific object from the ArrayList.
10
public virtual void RemoveAt(int index); 
Removes the element at the specified index of the ArrayList.
11
public virtual void RemoveRange(int index, int count); 
Removes a range of elements from the ArrayList.
12
public virtual void Reverse(); 
Reverses the order of the elements in the ArrayList.
13
public virtual void SetRange(int index, ICollection c); 
Copies the elements of a collection over a range of elements in the ArrayList.
14
public virtual void Sort(); 
Sorts the elements in the ArrayList.
15
public virtual void TrimToSize(); 
Sets the capacity to the actual number of elements in the ArrayList.