Tuesday, August 25, 2009

70-536 NET Foundations #28

Hey Now,

Please feel free to check out my MCTS 70-536 reference page on Chris Catto.com. It’s a page with a summary of all of my posts.
As I study for this test I thought this would be good to post on to learn the content & others would be able to view & comment on it.

This content below is from some practice questions from the internet & not sure the answers are correct. There were over 200 questions & some duplicates, I hope to study all of them. I’ve also added some of my notes to these so any line starting with K8 (my nickname, first syllable of Catt o ) are my comments.

Thx,

Catto

Q#121 – Q#39

Question: 121

You need to return the contents of an isolated storage file as a string. The file is machine-scoped and is named Settings.dat. Which code segment should you use?

A. Dim objStream As IsolatedStorageFileStreamobjStream = New IsolatedStorageFileStream( _ "Settings.dat", FileMode.Open)Dim result As String = New
StreamReader(objStream).ReadToEnd

B. Dim objFile As IsolatedStorageFileobjFile =
IsolatedStorageFile.GetMachineStoreForAssembly
Dim objStream As IsolatedStorageFileStreamobjStream = New IsolatedStorageFileStream( _
"Settings.dat", FileMode.Open, objFile)
Dim result As String = New StreamReader(objStream).ReadToEnd

C. Dim objStream As IsolatedStorageFileStreamobjStream = New
IsolatedStorageFileStream( _
"Settings.dat", FileMode.Open)Dim result As String objStream.toString

D. Dim objFile As IsolatedStorageFileobjFile =
IsolatedStorageFile.GetMachineStoreForAssembly
Dim objStream As IsolatedStorageFileStreamobjStream = New IsolatedStorageFileStream( _
"Settings.dat", FileMode.Open, objFile)
Dim result As String = objStream.ToString

Answer: B

K8 – IsolatedStorageFileobjFile along with ReadToEnd

Question: 122

You are developing a utility screen for a new client application. The utility screen displays a thermometer that conveys the current status of processes being carried out by the application. You need to draw a rectangle on the screen to serve as the background of the thermometer as shown in the exhibit. The rectangle must be filled with gradient shading. Which code segment should you choose?

Exhibit:

A. Rectangle rectangle = new Rectangle(10, 10, 450, 25); LinearGradientBrush rectangleBrush =
new LinearGradientBrush(rectangle, Color.AliceBlue,
Color.CornflowerBlue,
LinearGradientMode.ForwardDiagonal);
Pen rectanglePen = new Pen(rectangleBrush);
Graphics g = this.CreateGraphics(); g.DrawRectangle(rectanglePen, rectangle);

B. Rectangle rectangle = new Rectangle(10, 10, 450, 25); LinearGradientBrush rectangleBrush =
new LinearGradientBrush(rectangle, Color.AliceBlue,
Color.CornflowerBlue,
LinearGradientMode.ForwardDiagonal);
Pen rectanglePen = new Pen(rectangleBrush);
Graphics g = this.CreateGraphics(); g.FillRectangle(rectangleBrush, rectangle);

C. RectangleF rectangle = new RectangleF(10f, 10f, 450f, 25f); Point[] points = new Point[] {new Point(0, 0), new Point(110, 145)};
LinearGradientBrush rectangelBrush = new LinearGradientBrush(rectangle, Color.AliceBlue, Color.CornflowerBlue, LinearGradientMode.ForwardDiagonal);
Pen rectanglePen = new Pen(rectangleBrsh);
Graphics g = this.CreateGraphics(); g.DrawPolygon(rectanglePen, points);

D. RectangleF rectangle = new RectangleF(10f, 10f, 450f, 25f); SolidBrush rectangleBrush =
new SolidBrush(Color.AliceBlue); Pen rectanglePen = new Pen(rectangleBrush);
Graphics g = this.CreateGraphics(); g.DrawRectangle(rectangleBrush, rectangle);

Answer: B

K8 – Just Rectangle not RectangleF & when filling use the brush not pen.

Question: 123

You are developing an application to perform mathematical calculations. You develop a class named CalculationValues. You write a procedure named PerformCalculation that operates on an instance of the class. You need to ensure that the user interface of the application continues to respond while calculations are being performed. You need to write a code segment that calls the PerformCalculation procedure to achieve this goal. Which code segment should you use?

A. public ref class CalculationValues {}; public ref class Calculator {
public :
void PerformCalculation() {} }; public ref class ThreadTest{
private :
void DoWork (){
CalculationValues^ myValues = gcnew CalculationValues();
Calculator^ calc = gcnew Calculator();
Thread^ newThread = gcnew Thread(
gcnew ThreadStart(calc, &Calculator::PerformCalculation));
newThread->Start(myValues);
}};

B. public ref class Calculation Values {}; public ref class Calculator {
public :void PerformCalculation() {}}; public ref class ThreadTest{
private :

void DoWork (){
CalculationValues^ myValues = gcnew CalculationValues();
Calculator^ calc = gcnew Calculator();
ThreadStart^ delStart = gcnew
ThreadStart(calc, &Calculator::PerformCalculation);
Thread^ newThread = gcnew Thread(delStart);
if (newThread->IsAlive) {
newThread->Start(myValues);
}
}};

C. public ref class Calculation Values {}; public ref class Calculator {
public :
void PerformCalculation(CalculationValues^ values) {} };
public ref class ThreadTest{
private :
void DoWork (){
CalculationValues^ myValues = gcnew CalculationValues();
Calculator^ calc = gcnew Calculator();
Application::DoEvents();
calc->PerformCalculation(myValues);
Application::DoEvents();
}};

D. public ref class Calculation Values {}; public ref class Calculator {
public :
void PerformCalculation(Object^ values) {} }; public ref class ThreadTest{
private :
void DoWork (){
CalculationValues^ myValues = gcnew CalculationValues();
Calculator^ calc = gcnew Calculator();
Thread^ newThread = gcnew Thread(
gcnew ParameterizedThreadStart(calc,
&Calculator::PerformCalculation));
newThread->Start(myValues);
}};

Answer: D

K8 – Do calculations while still responding use ParameterizedTreadStart

Question: 124

You are developing a method to decrypt data that was encrypted with the Triple DES Algorithm. The method accepts the following parameters: The byte array to be decrypted, which is named cipherMessageThe key, which is named keyAn initialization vector, which is named iv You need to decrypt the message by using the TripleDES class and place the result in a string. Which code segment should you use?

A. Dim objDES As New TripleDESCryptoServiceProviderobjDES.BlockSize =
cipherMessage.Length
Dim objCrypto As ICryptoTransform = _
objDES.CreateDecryptor(key, iv)
Dim cipherStream As New
MemoryStream(cipherMessage)
Dim cryptoStream As New CryptoStream( _
cipherStream, objCrypto, CryptoStreamMode.Read)
Dim message As Stringmessage =
New StreamReader(cryptoStream).ReadToEnd

B. Dim objDES As New TripleDESCryptoServiceProviderobjDES.FeedbackSize =
cipherMessage.Length
Dim objCrypto As ICryptoTransform = _
objDES.CreateDecryptor(key, iv)
Dim cipherStream As New
MemoryStream(cipherMessage)
Dim cryptoStream As New CryptoStream( _
cipherStream, objCrypto, CryptoStreamMode.Read)
Dim message As Stringmessage =
New StreamReader(cryptoStream).ReadToEnd

C. Dim objDES As New TripleDESCryptoServiceProvider
Dim objCrypto As ICryptoTransform = _
objDES.CreateDecryptor()
Dim cipherStream As New
MemoryStream(cipherMessage)
Dim cryptoStream As New CryptoStream( _
cipherStream, objCrypto, CryptoStreamMode.Read)Dim message As Stringmessage =
New StreamReader(cryptoStream).ReadToEnd

D. Dim objDES As New TripleDESCryptoServiceProvider
Dim objCrypto As
ICryptoTransform = _
objDES.CreateDecryptor(key, iv)
Dim cipherStream As New
MemoryStream(cipherMessage)
Dim cryptoStream As New CryptoStream( _
cipherStream, objCrypto, CryptoStreamMode.Read)Dim message As Stringmessage =
New StreamReader(cryptoStream).ReadToEnd

Answer: D

K8 – with TripleDESCryptoServiceProvider no block or feedbacksize

Question: 125

You are developing a custom event handler to automatically print all open documents. The event handler helps specify the number of copies to be printed. You need to develop a custom event arguments class to pass as a parameter to the event handler. Which code segment should you use?

A. public ref class PrintingArgs {
public :
int Copies ;
PrintingArgs (int numberOfCopies) {
this->Copies = numberOfCopies;
}};

B. public ref class PrintingArgs : public EventArgs {
public :
int Copies ;
PrintingArgs(int numberOfCopies) {
this->Copies = numberOfCopies;
}};

C. public ref class PrintingArgs {
public :
EventArgs Args;
PrintingArgs(EventArgs ea) {
this->Args = ea;
}};

D. public ref class PrintingArgs : public EventArgs {
public :
int Copies;};

Answer: B

K8 – class PrintingArgs & event handler EventArgs print all copies & increment counter.

Question: 126

You are writing a method to compress an array of bytes. The array is passed to the method in a parameter named document. You need to compress the incoming array of bytes and return the result as an array of bytes. Which code segment should you use?

A. MemoryStream^ strm = gcnew MemoryStream(document);
DeflateStream^ deflate = gcnew DeflateStream(strm,
CompressionMode::Compress);
array<Byte>^ result = gcnew array<Byte>(document->Length);
deflate->Write(result, 0, result->Length);
return result;

B. MemoryStream^ strm = gcnew MemoryStream(document);
DeflateStream^ deflate = gcnew DeflateStream(strm,
CompressionMode::Compress);
deflate->Write(document, 0, document->Length);
deflate->Close();return strm->ToArray();

C. MemoryStream^ strm = gcnew MemoryStream();
DeflateStream^ deflate = gcnew
DeflateStream(strm,CompressionMode::Compress);
deflate->Write(document, 0, document->Length);
deflate->Close();
return strm->ToArray();

D. MemoryStream^ inStream = gcnew MemoryStream(document);DeflateStream^
deflate = gcnew DeflateStream(inStream,
CompressionMode::Compress);
MemoryStream^ outStream = gcnew MemoryStream()
;int b;
while ((b = deflate->ReadByte()) != -1) {
outStream->WriteByte((Byte)b);
}
return outStream->ToArray();

Answer: C

K8 – MemoryStream()

Question: 127

You are creating a class that performs complex financial calculations. The class contains a method named GetCurrentRate that retrieves the current interest rate and a variable named currRate that stores the current interest rate. You write serialized representations of the class. You need to write a code segment that updates the currRate variable with the current interest rate when an instance of the class is deserialized. Which code segment should you use?

A. <OnSerializing> _Friend Sub UpdateValue (ByVal context As StreamingContext)

currRate = GetCurrentRate()End Sub

B. <OnSerializing> _ Friend Sub UpdateValue(ByVal info As SerializationInfo)

info.AddValue("currentRate", GetCurrentRate())End Sub

C. <OnDeserializing> _ Friend Sub UpdateValue(ByVal info As SerializationInfo)

info.AddValue("currentRate", GetCurrentRate())End Sub

D. <OnDeserialized> _Friend Sub UpdateValue (ByVal context As StreamingContext)

currRate = GetCurrentRate()End Sub

Answer: D

K8 - OnDeserialized – when the instance of the class is deserialized.

You are writing an application that uses isolated storage to store user preferences. The application uses multiple assemblies. Multiple users will use this application on the same computer. You need to create a directory named Preferences in the isolated storage area that is scoped to the current Microsoft Windows identity and assembly. Which code segment should you use?

A. Dim objStore As IsolatedStorageFileobjStore =

IsolatedStorageFile.GetUserStoreForAssemblyobjStore.CreateDirectory("Preferences")

B. Dim objStore As IsolatedStorageFileobjStore =
IsolatedStorageFile.GetMachineStoreForAssemblyobjStore.CreateDirectory("Preferences")

C. Dim objStore As IsolatedStorageFileobjStore =
IsolatedStorageFile.GetUserStoreForDomainobjStore.CreateDirectory("Preferences")

D. Dim objStore As IsolatedStorageFileobjStore =
IsolatedStorageFile.GetUserStoreForApplicationobjStore.CreateDirectory("Preferences")

Answer: A

K8 – Q: multiple assemblies A: GetUserStoreForAssemblyobjStore

Question: 129

You are developing a method that searches a string for a substring. The method will be localized to Italy. Your method accepts the following parameters: The string to be searched, which is named searchList. The string for which to search, which is named searchValue You need to write the code. Which code segment should you use?

A return searchList.IndexOf(searchValue);

B. CompareInfo comparer = new CultureInfo(“it-IT”).CompareInfo;
return comparer.Compare(searchList, searchValue);

C. CultureInfo Comparer = new CultureInfo(“it-IT”);
if(searchList.IndexOf(searchValue)
> 0) {
return true;} else {
return false;}

D. CompareInfo comparer =
new CultureInfo(“it-IT”).CompareInfo;
if (comparer.IndexOf(searchList, searchValue) > 0) {
return true;} else {
return false;}

Answer: D

K8 – Use comparer.IndexOf

Question: 130

You are creating a class named Age. You need to ensure that the Age class is written such that collections of Age objects can be sorted. Which code segment should you use?

A. Public Class Age
Public Value As Integer
Public Function CompareTo(ByVal obj As Object) As Objec t
If TypeOf obj Is Age Then
Dim _age As Age = CType(obj, Age)
Return Value.CompareTo(obj)
End If
Throw New ArgumentException("object not an Age")
End FunctionEnd Class

B. Public Class Age
Public Value As Integer
Public Function CompareTo(ByVal iValue As Integer) As Object
Try
Return Value.CompareTo(iValue)
Catch
Throw New ArgumentException ("object not an Age")
End Try
End FunctionEnd Class

C. Public Class Age
Implements IComparable
Public Value As Integer
Public Function CompareTo(ByVal obj As Object) As Integer _
Implements IComparable.CompareTo
If TypeOf obj Is Age Then
Dim _age As Age = CType(obj, Age)
Return Value.CompareTo(_age.Value)
End If
Throw New ArgumentException("object not an Age")
End FunctionEnd Class

D. Public Class Age
Implements IComparable
Public Value As Integer
Public Function CompareTo(ByVal obj As Object) As Integer _
Implements IComparable.CompareTo
Try
Return Value.CompareTo((CType(obj, Age)).Value)
Catch
Return -1
End Try
End FunctionEnd Class

Answer: C

K8 – Able to sort A: Icomparable & not try needed.

Question: 131

You are developing a class library. Portions of your code need to access system environment variables. You need to force a runtime SecurityException only when callers that are higher in the call stack do not have the necessary permissions. Which call method should you use?

A. Demand()

B. Assert()

C. PermitOnly()

D. Deny()

Answer: A

K8 – Q: force rentime securityException when callers that don’t have permission. A: Demand()

Question: 132

You are testing a component that serializes the Meeting class instances so that they can be saved to the file system. The Meeting class has the following definition:

Public Class Meeting
Private title As String
Public roomNumber As Integer
Public invitees As String()
Public Sub New()End Sub
Public Sub New(ByVal t As String)
title = t
End Sub End Class
The component contains a procedure with the following code segment.

Dim myMeeting As New Meeting("Goals") myMeeting.roomNumber = 1100
Dim attendees As String() = New String(1) {"Company", "Mary"} myMeeting.invitees = attendees
Dim xs As New XmlSerializer(GetType(Meeting)) Dim writer As New
StreamWriter("C:\Meeting.xml") xs.Serialize(writer, myMeeting) writer.Close()
You need to identify the XML block that is written to the C:\Meeting.xml file as a result of running this procedure. Which XML block represents the content that will be written to the C:\Meeting.xml file?

A. <?xml version="1.0" encoding="utf-8"?>
<Meeting xmlns:xsd=http://www.w3.org/2001/XMLSchema
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<title>Goals</title>
<roomNumber>1100</roomNumber>
<invitee>Company</invitee>
<invitee>Mary</invitee>
</Meeting>

B. <?xml version="1.0" encoding="utf-8"?>
<Meeting xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<roomNumber>1100</roomNumber>
<invitees>
<string>Company</string>
<string>Mary</string>
</invitees>
</Meeting>

C. <?xml version="1.0" encoding="utf-8"?>
<Meeting xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

title="Goals">
<roomNumber>1100</roomNumber>
<invitees>
<string>Company</string>
<string>Mary</string>
</invitees>
</Meeting>

D. <?xml version="1.0" encoding="utf-8"?>
<Meeting xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<roomNumber>1100</roomNumber>
<invitees>
<string>Company</string>
</invitees>
<invitees>
<string>Mary</string>
</invitees>
</Meeting>

Answer: B

K8 – no title tag like in C

Question: 133

You are developing a method that searches a string for a substring. The method will be localized to Italy. Your method accepts the following parameters: The string to be searched, which is named SearchListThe string for which to search, which is named SearchValue You need to write the code. Which code segment should you use?

A. Return SearchList.IndexOf(SearchValue)

B. Dim objComparer As CompareInfo = _
New CultureInfo("it-IT").CompareInfoReturn objComparer.Compare(SearchList, SearchValue)

C. Dim objComparer As CompareInfo = _
New CultureInfo("it-IT").CompareInfoIf SearchList.IndexOf(SearchValue) > 0 Then
Return TrueElse
Return FalseEnd If

D. Dim objComparer As CompareInfo = _
New CultureInfo("it-IT").CompareInfoIf objComparer.IndexOf(SearchList,
SearchValue) > 0 Then
Return TrueElse
Return FalseEnd If

Answer: D

K8 - String from substring

Question: 134

You are developing a method to encrypt sensitive data with the Data Encryption Standard (DES) algorithm. Your method accepts the following parameters:

The byte array to be encrypted, which is named messageAn encryption key, which is named keyAn initialization vector, which is named iv You need to encrypt the data. You also need to write the encrypted data to a MemoryStream object. Which code segment should you use?

A. Dim objDES As New DESCryptoServiceProviderobjDES.BlockSize =
message.Length
Dim objCrypto As ICryptoTransform = obj
DES.CreateDecryptor(key, iv)
Dim cipherStream As New MemoryStream
Dim cryptoStream As New CryptoStream(cipherStream, objCrypto, CryptoStreamMode.Write)

B. Dim objDES As New DESCryptoServiceProvider

Dim objCrypto As ICryptoTransform = objDES.CreateDecryptor(key, iv)
Dim cipherStream As New MemoryStream
Dim cryptoStream As New CryptoStream(cipherStream, objCrypto, CryptoStreamMode.Write)
cryptoStream.Write(message, 0, message.Length)

C. Dim objDES As New DESCryptoServiceProvider
Dim objCrypto As ICryptoTransform = obj
DES.CreateDecryptor()
Dim cipherStream As New MemoryStream
Dim cryptoStream As New CryptoStream(cipherStream, objCrypto, CryptoStreamMode.Write)
cryptoStream.Write(message, 0, message.Length)

D. Dim objDES As New DESCryptoServiceProvider
Dim objCrypto As ICryptoTransform =

objDES.CreateEncryptor(key, iv)
Dim cipherStream As New MemoryStream
Dim cryptoStream As New CryptoStream(cipherStream, objCrypto, CryptoStreamMode.Write)
cryptoStream.Write(message, 0, message.Length)

Answer: D

K8 – CreateEncryptor since encrypting

Question: 135

You are creating an application that retrieves values from a custom section of the application configuration file. The custom section uses XML as shown in the following block.

<ProjectSection name="ProjectCompany">
<role name="administrator" />
<role name="manager" />
<role name="support" />
</ProjectSection>

You need to write a code segment to define a class named Role. You need to ensure that the Role class is initialized with values that are retrieved from the custom section of the configuration
file. Which code segment should you use?

A. Public Class RoleInherits ConfigurationElementFriend _ElementName As String =
"name"
<ConfigurationProperty("role")> _
Public ReadOnly Property Name() As String
Get
Return CType(Me("role"), String)
End Get
End PropertyEnd Class

B. Public Class Role

Inherits ConfigurationElement
Friend _ElementName As String = "role"
<ConfigurationProperty("name", IsRequired:=True)> _
Public ReadOnly Property Name() As String
Get
Return CType(Me("name"), String)
End Get
End PropertyEnd Class

C. Public Class Role
Inherits ConfigurationElement
Friend _ElementName As String = "role"
Private _name As String
<ConfigurationProperty("name")> _
Public ReadOnly Property Name() As String
Get
Return _name
End Get
End PropertyEnd Class
D. Public Class Role
Inherits ConfigurationElement
Friend _ElementName As String = "name"
Private _name As String
<ConfigurationProperty("role", IsRequired:=True)> _
Public ReadOnly Property Name() As String
Get
Return _name
End Get
End PropertyEnd Class

Answer: B

K8 - ", IsRequired:=True)> & return Name

Question: 136

You need to serialize an object of type List<int> in a binary format. The object is named data. Which code segment should you use?

A. BinaryFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
formatter.Serialize(stream, data);

B. BinaryFormatter formatter = new BinaryFormatter();
MemoryStream stream = new
MemoryStream();
for (int i = 0; i < data.Count, i++) {
formatter.Serialize(stream, data[i]);}

C. BinaryFormatter formatter = new BinaryFormatter();
byte[] buffer = new byte[data.Count];
MemoryStream stream = new MemoryStream(buffer, true);
formatter.Serialize(s tream, data);

D. BinaryFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
data.ForEach(delegate(int num)
{ formatter.Serialize(stream, data); }
);

Answer: A

K8 – BinaryFormatter formatter.Serialize(stream, data);

Question: 137

You are writing a method to compress an array of bytes. The bytes to be compressed are passed to the method in a parameter named document. You need to compress the contents of the incoming parameter. Which code segment should you use?

A. MemoryStream inStream = new MemoryStream(document);
GZipStream zipStream = new GZipStream(inStream,
CompressionMode.Compress);
byte[] result = new

Byte[document.Length];
zipStream.Write(result, 0, result.Length);
return result;

B. MemoryStream Stream = new MemoryStream(document);
GZipStream zipStream = new GZipStream(stream,
CompressionMode.Compress);
zipStream.Write(document, 0, document.Length);
zipStream.Close();
return stream.ToArray();

C. MemoryStream outStream = new MemoryStream();
GZipStream zipStream = new GZipStream(outStream,
CompressionMode.Compress);
zipStream.Write(document, 0, document.Length);
zipStream.Close();
return outStream.ToArray();

D. MemoryStream inStream = new MemoryStream(document);GZipStream zipStream =
new GZipStream(inStream,
CompressionMode.Compress);
MemoryStream outStream = new MemoryStream();int b;while
((b = zipStream.ReadByte()) != -1) {
outStream.WriteByte((byte)b);
} return outStream.ToArray();

Answer: C

K8 – Q: compress A: MemoryStream(); Gzip compress

Question: 138

You write the following code to implement the CompanyClass.MyMethod function.
Public Class NewClass
Public Function MyMethod(ByVal Arg As Integer) As Integer
Return Arg
End FunctionEnd Class

You need to call the CompanyClass.MyMethod function dynamically from an unrelated class in your assembly. Which code segment should you use?

A. Dim objNewClass As New NewClassDim objType As Type =
objNewClass.GetType
Dim objInfo As MethodInfo = _
objType.GetMethod("MyMethod")
Dim objParams() As Object = {1}
Dim i As Integer = _
DirectCast(objInfo.Invoke(Me, objParams), Integer)

B. Dim objNewClass As New NewClass
Dim objType As Type = objNewClass.GetType
Dim objInfo As MethodInfo =
objType.GetMethod("MyMethod")
Dim objParams() As Object = {1}
Dim i As Integer = _
DirectCast(objInfo.Invoke(objNewClass, objParams), Integer)

C. Dim objNewClass As New NewClass
Dim objType As Type =
objNewClass.GetTypeDim objInfo As MethodInfo = _
objType.GetMethod("NewClass.MyMethod")Dim objParams() As Object = {1}Dim i As
Integer = _
DirectCast(objInfo.Invoke(objNewClass, objParams), Integer)

D. Dim objType As Type = Type.GetType("NewClass")
Dim objInfo As MethodInfo =
objType.GetMethod("MyMethod")
Dim objParams() As Object = {1}
Dim i As Integer = _
DirectCast(objInfo.Invoke(Me, objParams), Integer)

Answer: B

K8 - Invoke(objNewClass

Question: 139

You are developing a method to decrypt data that was encrypted with the Triple DES Algorithm. The method accepts the following parameters: The byte array to be decrypted, which is named cipherMessageThe key, which is named keyAn initialization vector, which is named iv You need to decrypt the message by using the TripleDES class and place the result in a string. Which code segment should you use?

A. TripleDES^ des = gcnew TripleDESCryptoServiceProvider();des->BlockSize = cipherMessage->Length;
ICryptoTransform^ crypto = des->CreateDecryptor(key, iv);
MemoryStream^ cipherStream = gcnew MemoryStream(cipherMessage);
CryptoStream ^cryptoStream = gcnew CryptoStream(cipherStream, crypto, CryptoStreamMode::Read);
String^ message;StreamReader^ sReader = gcnew StreamReader(cryptoStream);
message = sReader->ReadToEnd();

B. TripleDES^ des = gcnew TripleDESCryptoServiceProvider();
des->FeedbackSize = cipherMessage->Length;
ICryptoTransform^ crypto = des->CreateDecryptor(key, iv);
MemoryStream^ cipherStream = gcnew MemoryStream(cipherMessage);
CryptoStream^ cryptoStream = gcnew CryptoStream(cipherStream, crypto,CryptoStreamMode::Read);
String^ message;StreamReader^ sReader = gcnew StreamReader(cryptoStream);
message = sReader->ReadToEnd();

C. TripleDES^ des = gcnew TripleDESCryptoServiceProvider();
ICryptoTransform^ crypto = des->CreateDecryptor();
MemoryStream^ cipherStream = gcnew MemoryStream(cipherMessage);
CryptoStream^ cryptoStream = gcnew CryptoStream(cipherStream, crypto,
CryptoStreamMode::Read);String^ message;
StreamReader^ sReader = gcnew StreamReader(cryptoStream);
message = sReader->ReadToEnd();

D. TripleDES^ des = gcnew TripleDESCryptoServiceProvider();
ICryptoTransform^ crypto = des->CreateDecryptor(key, iv);
MemoryStream^ cipherStream = gcnew MemoryStream(cipherMessage);
CryptoStream^ cryptoStream = gcnew CryptoStream( cipherStream, crypto,
CryptoStreamMode::Read);

String^ message;StreamReader^ sReader = gcnew StreamReader(cryptoStream);
message = sReader->ReadToEnd();

Answer: D

K8 – TripleDes Decrypting

No comments: