Rijndael algoritması bir kare varyasyon algoritmasıdır.
Çok iyi,çok hızlı ve çok performanslı çalışan ileri boyutta düzgün matematiksel iç yapıya sahip bir algoritma düzeni vardır.Daha önceki makalemde söylediğim gibi en iyi beş AES algoritması arasında birinci olmuştur.
Rijndael algoritması yazılım boyutun güzel bir entegrasyon yakaladığı gibi donanım boyutundada çok iyi uyum sağlar.
Rijndael algoritmasının göze batan iki dezavantajı vardır.Bunlardan biri uzun anahtar boyutlarını uzunca bir zamanda şifrelemesidir.İkincisi ise 256 bit anahtar kullanımlarında döngüsel artım olduğu için hızı yüksek boyutta düşer.
Rijndael algoritmasına .net platformuna geçmeden önce c/c++ üzerinden bir örnekle bakalım.
nrounds = rijndaelSetupEncrypt(rk, key, keybits); for encryption
nrounds = rijndaelSetupDecrypt(rk, key, keybits); for decryption
unsigned long *rk; pointer to encryption/decryption buffer,
required space:
keybits 32-bit words required
128 44
192 52
256 60
const unsigned char *key; key, where length in bytes is:
keybits number of bytes
128 16
192 24
256 32
int keybits; number of bits in key,must be 128, 192 or
256
int nrounds;
number of rounds:
keybits nrounds
128 10
192 12
256 14
rijndaelEncrypt(rk, nrounds, plaintext, ciphertext);
rijndaelDecrypt(rk, nrounds, ciphertext, plaintext);
const unsigned long *rk;
pointer to encryption/decryption buffer which
was filled by rijndaelSetupEncrypt() or
rijndaelSetupDecrypt()
int nrounds; number of rounds, as computed by
rijndaelSetupEncrypt(),
rijndaelSetupDecrypt() or NROUNDS
[const] unsigned char plaintext[16];
[const] unsigned char ciphertext[16];
pointers to 16-byte buffers to be encrypted
or decrypted; the source buffer has a const
Rijndael algoritması; ard arda permütasyon kullanarak şifreleme özelliğine sahip bir algoritmadır.Zaten DES algoritmasıda ard arda permütasyon yapan bir algoritmaydı ve AES(Rijndael) DES algoritmasının alternatifi olarak çıkarılmış bir algoritmaydı.
Şimdi .Net platformumuza dönüyoruz…..
.net üstünde öncelikle kullanacağımız syntax lara bakalım.
VB
<ComVisibleAttribute(True)> _Public NotInheritable Class RijndaelManaged _Inherits Rijndael Dim instance As RijndaelManaged
C#
[ComVisibleAttribute(true)]public sealed class RijndaelManaged : Rijndael
C++ .NET
[ComVisibleAttribute(true)]public ref class RijndaelManaged sealed : public Rijndael Bu algoritma tabikide yine AES algoritmasında olduğu gibi 128, 192 ve 256 bitlik anahtar boyutları kullanır. Küçük Kod Parçaları ile başlayalım
Örn:
public abstract class Rijndael: SymmetricAlgorithm
{
public Rijndael ()
: base()
{
KeySizeValue = 128;
BlockSizeValue = 128;
FeedbackSizeValue = 128;
LegalBlockSizesValue = new KeySizes [1];
LegalBlockSizesValue[0] = new KeySizes(128, 128, 128);
LegalKeySizesValue = new KeySizes [1];
LegalKeySizesValue[0] = new KeySizes(128, 256, 64);
}Rijndael
public new static Rijndael Create()
{
return (Rijndael)(CryptoConfig.CreateFromName
(CryptoConfig. Rijndael Default, null));
}
public new static Rijndael Create(String algName)
{
return (Rijndael)(CryptoConfig.CreateFromName(algName, null));
}
Geniş bir konsept uygulamayla devam ediyoruz…..
Uyg:
using System;
using System.IO;
using System.Security.Cryptography;
namespace RijndaelManaged_Examples
{
class RijndaelMemoryExample
{
public static void Main()
{
try
{
string original = "Here is some data to encrypt!";
RijndaelManaged myRijndael = new RijndaelManaged();
byte[] encrypted = encryptStringToBytes_AES(original, myRijndael.Key, myRijndael.IV);
string roundtrip = decryptStringFromBytes_AES(encrypted, myRijndael.Key, myRijndael.IV);
Console.WriteLine("Original: {0}", original);
Console.WriteLine("Round Trip: {0}", roundtrip);
}
catch (Exception e)
{
Console.WriteLine("Error: {0}", e.Message);
}
}
static byte[] encryptStringToBytes_AES(string plainText, byte[] Key, byte[] IV)
{
if (plainText == null || plainText.Length <= 0)
throw new ArgumentNullException("plainText");
if (Key == null || Key.Length <= 0)
throw new ArgumentNullException("Key");
if (IV == null || IV.Length <= 0)
throw new ArgumentNullException("Key");
MemoryStream msEncrypt = null;
RijndaelManaged aesAlg = null;
try
{
aesAlg = new RijndaelManaged();
aesAlg.Key = Key;
aesAlg.IV = IV;
ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
msEncrypt = new MemoryStream();
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
{
using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
{
swEncrypt.Write(plainText);
}
}
}
finally
{
if (aesAlg != null)
aesAlg.Clear();
}
return msEncrypt.ToArray();
}
static string decryptStringFromBytes_AES(byte[] cipherText, byte[] Key, byte[] IV)
{
if (cipherText == null || cipherText.Length <= 0)
throw new ArgumentNullException("cipherText");
if (Key == null || Key.Length <= 0)
throw new ArgumentNullException("Key");
if (IV == null || IV.Length <= 0)
throw new ArgumentNullException("Key");
RijndaelManaged aesAlg = null;
string plaintext = null;
try
{
aesAlg = new RijndaelManaged();
aesAlg.Key = Key;
aesAlg.IV = IV;
ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
using (MemoryStream msDecrypt = new MemoryStream(cipherText))
{
using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
{
using (StreamReader srDecrypt = new StreamReader(csDecrypt))
plaintext = srDecrypt.ReadToEnd();
}
}
}
finally
{
.
if (aesAlg != null)
aesAlg.Clear();
}
return plaintext;
}
}
}
SON SÖZ
Rijndael algoritması gerçekten önemli bir algoritma.Gerek teorik gerek pratik açıdan gerekse c/c++ kodlarla tam mantığı oturtmanız açısından yeterli bir kaynak olucağını düşünüyorum.