CryptoProvider.Decrypt(Byte[]) Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Decrypts cipher text to clear text.
public:
cli::array <System::Byte> ^ Decrypt(cli::array <System::Byte> ^ cryptoText);
public byte[] Decrypt (byte[] cryptoText);
member this.Decrypt : byte[] -> byte[]
Public Function Decrypt (cryptoText As Byte()) As Byte()
- cryptoText
- Byte[]
The cipher text to decrypt.
The decrypted clear text of cryptoText
.
cipherText
is null.
Decryption right not granted.
The following example shows how to use the Decrypt method to convert encrypted data to unencrypted data.
byte[] imageBuffer;
using (Stream cipherTextStream = File.OpenRead(encryptedFile))
{
byte[] contentLengthByteBuffer = new byte[sizeof(Int32)];
// Read the length of the source content file
// from the first four bytes of the encrypted file.
ReliableRead(cipherTextStream, contentLengthByteBuffer,
0, sizeof(Int32));
// Allocate the clearText buffer.
int contentLength =
BitConverter.ToInt32(contentLengthByteBuffer, 0);
imageBuffer = new byte[contentLength];
// Allocate the cipherText block.
byte[] cipherTextBlock =
new byte[cryptoProvider.BlockSize];
// decrypt cipherText to clearText block by block.
int imageBufferIndex = 0;
for ( ; ; )
{ // Read cipherText block.
int readCount = ReliableRead(
cipherTextStream,
cipherTextBlock, 0,
cryptoProvider.BlockSize);
// readCount of zero is end of data.
if (readCount == 0)
break; // for
// Decrypt cipherText to clearText.
byte[] clearTextBlock =
cryptoProvider.Decrypt(cipherTextBlock);
// Copy the clearTextBlock to the imageBuffer.
int copySize = Math.Min(clearTextBlock.Length,
contentLength-imageBufferIndex);
Array.Copy(clearTextBlock, 0,
imageBuffer, imageBufferIndex, copySize);
imageBufferIndex += copySize;
}
}// end:using (Stream cipherTextStream = (close/dispose)
Dim imageBuffer() As Byte
Using cipherTextStream As Stream = File.OpenRead(encryptedFile)
Dim expression As Int32
Dim contentLengthByteBuffer(Len(expression) - 1) As Byte
' Read the length of the source content file
' from the first four bytes of the encrypted file.
ReliableRead(cipherTextStream, contentLengthByteBuffer, 0, Len(expression))
' Allocate the clearText buffer.
Dim contentLength As Integer = BitConverter.ToInt32(contentLengthByteBuffer, 0)
imageBuffer = New Byte(contentLength - 1) {}
' Allocate the cipherText block.
Dim cipherTextBlock(cryptoProvider.BlockSize - 1) As Byte
' decrypt cipherText to clearText block by block.
Dim imageBufferIndex As Integer = 0
Do
Dim readCount As Integer = ReliableRead(cipherTextStream, cipherTextBlock, 0, cryptoProvider.BlockSize)
' readCount of zero is end of data.
If readCount = 0 Then
Exit Do ' for
End If
' Decrypt cipherText to clearText.
Dim clearTextBlock() As Byte = cryptoProvider.Decrypt(cipherTextBlock)
' Copy the clearTextBlock to the imageBuffer.
Dim copySize As Integer = Math.Min(clearTextBlock.Length, contentLength - imageBufferIndex)
Array.Copy(clearTextBlock, 0, imageBuffer, imageBufferIndex, copySize)
imageBufferIndex += copySize
Loop
End Using ' end:using (Stream cipherTextStream = (close/dispose)
Προϊόν | Εκδόσεις |
---|---|
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
.NET σχόλια
.NET είναι ένα έργο ανοιχτού κώδικα. Επιλέξτε μια σύνδεση για να παρέχετε σχόλια: