See Also

SymmetricCryptoStream Class  | SymmetricCryptoStream Members

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Language

Visual Basic

C#

C++

C++/CLI

Show All

See Also Languages PowerTCP SSL Sockets for .NET

Algorithm Property

Dart.PowerTCP.SslSockets Namespace > SymmetricCryptoStream Class : Algorithm Property

Exposes the algorithm cryptographic service provider used to initialize the SymmetricCryptoStream.

[Visual Basic]
Public ReadOnly Property Algorithm As SymmetricAlgorithm
[C#]
public SymmetricAlgorithm Algorithm {get;}
[C++]
public: __property SymmetricAlgorithm* get_Algorithm();
[C++/CLI]
public: property SymmetricAlgorithm^ Algorithm {    SymmetricAlgorithm^ get(); }

Remarks

Use this property to gain information about the AlgorithmType chosen. For example, you can access the legal key sizes for this algorithm via the SymmetricAlgorithm.LegalKeySizes property.

Example

The following example demonstrates displaying information about a symmetric algorithm by accessing the SymmetricCryptoStream.Algorithm property.

[Visual Basic] 

Private Sub DisplayAlgoInfo(ByVal algorithm as AlgorithmType)
   ' Create dummy key and data
   Dim key As Byte() = System.Text.Encoding.Default.GetBytes("test key")
   Dim data As Byte() = System.Text.Encoding.Default.GetBytes("test data")
   Dim mem as New MemoryStream(data)

   ' Initialize a new SymmetricCryptoStream
   Dim sc as New SymmetricCryptoStream(algorithm, key, mem)

   ' Display info about the algorithm used
   txtData.Text = "Block size: " + sc.Algorithm.BlockSize + vbCrLf
   txtData.Text += "Feedback size: " + sc.Algorithm.FeedbackSize + vbCRLF
   txtData.Text += "Key size: " + sc.Algorithm.KeySize + vbCrLf
   txtData.Text += "Mode: " + sc.Algorithm.Mode + vbCrLf
   txtData.Text += "Legal block sizes:" + vbCrLf
   Dim ks as KeySizes
   For Each ks in sc.Algorithm.LegalBlockSizes
      Dim i as Integer
      For i=ks.MinSize To ks.MaxSize Step ks.SkipSize
         txtData.Text += i + vbCrLf
         If ks.SkipSize = 0 Then
            Exit For
         End If
      Next
   Next
   txtData.Text += "Legal key sizes:" + vbCrLf
   For Each ks in sc.Algorithm.LegalKeySizes
      Dim i as Integer
      For i=ks.MinSize To ks.MaxSize Step ks.SkipSize
         txtData.Text += i + vbCrLf
         If ks.SkipSize = 0 Then
            Exit For
         End If
      Next
   Next
End Sub

[C#] 


private void DisplayAlgoInfo(AlgorithmType algorithm)
{
  
// Create dummy key and data
  
byte[] key = System.Text.Encoding.Default.GetBytes("test key");
  
byte[] data = System.Text.Encoding.Default.GetBytes("test data");
  MemoryStream mem =
new MemoryStream(data);
  
  
// Initialize a new SymmetricCryptoStream
  
SymmetricCryptoStream sc = new SymmetricCryptoStream(algorithm, key, mem);
               
  
// Display info about  the algorithm used
  
txtData.Text = "Block size: " + sc.Algorithm.BlockSize + "\r\n";
  txtData.Text +=
"Feedback size: " + sc.Algorithm.FeedbackSize + "\r\n";
  txtData.Text +=
"Key size: " + sc.Algorithm.KeySize + "\r\n";
  txtData.Text +=
"Mode: " + sc.Algorithm.Mode + "\r\n";
  txtData.Text +=
"Legal block sizes:\r\n";
  
foreach(KeySizes ks in sc.Algorithm.LegalBlockSizes)
     
for(int i=ks.MinSize; i<=ks.MaxSize; i+=ks.SkipSize)
     {
        txtData.Text += i +
"\r\n";
        
if(ks.SkipSize == 0)
           
break;
     }
  txtData.Text +=
"Legal key sizes:\r\n";
  
foreach(KeySizes ks in sc.Algorithm.LegalKeySizes)
      
for(int i=ks.MinSize; i<=ks.MaxSize; i+=ks.SkipSize)
      {
         txtData.Text += i +
"\r\n";
         
if(ks.SkipSize == 0)
            
break;
      }
}
                

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

SymmetricCryptoStream Class  | SymmetricCryptoStream Members


Send comments on this topic.

Documentation version 1.1.2.0.

© 2008 Dart Communications.  All rights reserved.