Woops, i should have left that bit of code in the sample
d is a variable that represents the instance of DESCryptoServiceProvider.
All symmetric cipher classes have a BlockSize property, and the IV size is
equal to the block size.
The BlockSize property is specified in bits, so you have to divide by 8.
-Rob Teixeira [MVP]
"John Young" <polomint77ATAThotmail.com> wrote in message
news:u5f$(E-Mail Removed)...
> Hmm, what is 'd.BlockSize'?
>
> Thanks
>
> John
>
>
> "Rob Teixeira [MVP]" <RobTeixeira@@msn.com> wrote in message
> news:%(E-Mail Removed)...
> > VB.NET
> > Dim iv As Byte() = New Byte(CInt(d.BlockSize / 8) - 1) {}
> > Dim rng As RandomNumberGenerator = RandomNumberGenerator.Create()
> > rng.GetNonZeroBytes(iv)
> >
> >
> > C#
> > byte[] iv = new byte[d.BlockSize / 8];
> > RandomNumberGenerator rng = RandomNumberGenerator.Create();
> > rng.GetNonZeroBytes(iv);
> >
> > You'll need to import the System.Security.Cryptography namespace to get
> > the
> > RandomNumberGenerator class.
> >
> > -Rob Teixeira [MVP]
> >
> > "John Young" <polomint77ATAThotmail.com> wrote in message
> > news:(E-Mail Removed)...
> >> Hi,
> >>
> >> I have written a couple of routines which encrypt and decrypt data
> >> using
> >> DESCryptoServiceProvider. Currently, the user has to pass in the
string
> > to
> >> encrypt, the key and the IV to the routine. Is there a good way of
> > creating
> >> the IV randomly so that the user does not need to create one
themselves?
> > I
> >> will pass the IV back to the user using an out parameter.
> >> Would I use some kind of random generator?
> >>
> >> Thanks in advance.
> >>
> >> John Young
> >>
> >>
> >
> >
>
>
|