[Mono-dev] Question about TransformFinalBlock with SymmetricAlgorithms and CBC

David Wolinsky davidiw at ufl.edu
Fri Jan 30 12:27:36 EST 2009


Hey guys,

Just wanted to let you know a behavioral difference between .Net and 
Mono and potentially get advice from you.  The method 
SA.CreateEncryptor.TransformFinalBlock() differs on the two platforms.  
Specifically, Mono appears to continue from where the last one ended, 
whereas .Net repeats itself (i.e. the IV is the same IV you inserted 
when the ICryptoTransform was created).

Below is a sample.

using System;
using System.Security.Cryptography;

public class tdes_test {
  public static void Main() {
    RijndaelManaged rm = new RijndaelManaged();
    byte[] key = new byte[rm.KeySize / 8];
    for(int i = 0; i < key.Length; i++) {
      key[i] = (byte) i;
    }
    byte[] iv = new byte[rm.BlockSize / 8];
    for(int i = 0; i < iv.Length; i++) {
      iv[i] = (byte) i;
    }
    ICryptoTransform encryptor = rm.CreateEncryptor(key, iv);
    byte[] data = new byte[111];
    for(int i = 0; i < data.Length; i++) {
      data[i] = (byte) i;
    }

    byte[] encrypted_data = encryptor.TransformFinalBlock(data, 0, 
data.Length);
    for(int i = 0; i < encrypted_data.Length; i++) {
      Console.Write(encrypted_data[i]);
    }
    Console.WriteLine("\n");
    encrypted_data = encryptor.TransformFinalBlock(data, 0, data.Length);
    for(int i = 0; i < encrypted_data.Length; i++) {
      Console.Write(encrypted_data[i]);
    }
  }
}


We're currently using this on a datagram security system and on Mono 
(not sure if .Net is the same) creation of Encryptors and Decryptors is 
expensive.  Any thoughts or suggestions?

Regards,
David


More information about the Mono-devel-list mailing list