|
That's the one.
Thanks very much.
|
|
|
|
|
I have this code in my project:
<br />
string str;<br />
byte[] enc = new byte[str.length];<br />
enc = Convert.FromBase64String(str);<br />
when i trace it, in the 2nd line the enc is a byte with the length of str but when 3rd line executes the enc length becomes 1 and therefore my data is not valid at the end.
does anybody know what should i do?
Roshanak
|
|
|
|
|
You should know that the base64 encoding is a bit verbose.
I.e. Silly question, silly answer (i.e. please post input values, expected output, actual output if you want better help).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
You didn't assign any string to str.
What do you expect enc should be?
*12Code
|
|
|
|
|
The assignment part of second line is not having any use. Your field will be having the return value from FromBase64String method.
Also the length of encrypted string and decrypted string wont be same.
|
|
|
|
|
I'm trying to encrypt sth, and those lines were just a part of my code. I'm sorry for not being clear but i wanted to be brief,
this is the whole code:
<br />
using System;<br />
using System.IO;<br />
using System.Text;<br />
using System.Security.Cryptography;<br />
<br />
namespace Cryptography<br />
{<br />
<br />
public sealed class Cryption<br />
{<br />
private RijndaelManaged Algorithm;<br />
<br />
private string m_key;<br />
private string m_iv;<br />
<br />
private byte[] key;<br />
private byte[] iv;<br />
<br />
<br />
<br />
public Cryption(string key_val, string iv_val)<br />
{<br />
key = new byte[32];<br />
iv = new byte[32];<br />
<br />
int i;<br />
m_key = key_val;<br />
m_iv = iv_val;<br />
<br />
for (i = 0; i < m_key.Length; i++)<br />
{<br />
key[i] = Convert.ToByte(m_key[i]);<br />
}<br />
for (i = 0; i < m_iv.Length; i++)<br />
{<br />
iv[i] = Convert.ToByte(m_iv[i]);<br />
}<br />
<br />
}<br />
<br />
<br />
public string Encrypt(string s)<br />
{<br />
string enc_str;<br />
byte[] enc_byte;<br />
<br />
Algorithm = new RijndaelManaged();<br />
<br />
Algorithm.BlockSize = 256;<br />
Algorithm.KeySize = 256;<br />
Algorithm.Padding = PaddingMode.PKCS7;<br />
<br />
<br />
using (MemoryStream memStream = new MemoryStream())<br />
{<br />
using (ICryptoTransform EncryptorDecryptor = Algorithm.CreateEncryptor(key, iv))<br />
{<br />
using (CryptoStream crStream = new CryptoStream(memStream, EncryptorDecryptor, CryptoStreamMode.Write))<br />
{<br />
UTF8Encoding utf8enc = new UTF8Encoding();<br />
enc_byte = utf8enc.GetBytes(s);<br />
crStream.Write(enc_byte, 0, enc_byte.Length);<br />
crStream.FlushFinalBlock();<br />
}<br />
}<br />
}<br />
<br />
<br />
enc_str = Convert.ToBase64String(enc_byte);<br />
return enc_str;<br />
<br />
}<br />
<br />
<br />
<br />
public string Decrypt(string s)<br />
{<br />
string dec_str;<br />
byte[] decrepted_byte;<br />
<br />
Algorithm = new RijndaelManaged();<br />
<br />
Algorithm.BlockSize = 256;<br />
Algorithm.KeySize = 256;<br />
Algorithm.Padding = PaddingMode.PKCS7;<br />
<br />
<br />
byte[] dec_byte = new byte[s.Length];<br />
dec_byte = Convert.FromBase64String(s);<br />
decrepted_byte = new byte[dec_byte.Length];<br />
<br />
using (MemoryStream memStream = new MemoryStream(dec_byte))<br />
{<br />
using (ICryptoTransform EncryptorDecryptor = Algorithm.CreateDecryptor(key, iv))<br />
{<br />
using (CryptoStream crStream = new CryptoStream(memStream, EncryptorDecryptor, CryptoStreamMode.Read))<br />
{<br />
crStream.Read(decrepted_byte, 0, decrepted_byte.Length);<br />
}<br />
}<br />
}<br />
<br />
UTF8Encoding utf8enc = new UTF8Encoding();<br />
dec_str = utf8enc.GetString(decrepted_byte);<br />
return dec_str;<br />
<br />
}<br />
<br />
}<br />
}<br />
so, you see none of the answers could help me!
|
|
|
|
|
Roshanakak wrote: none of the answers could help me!
because you gave fictitious code to start with.
|
|
|
|
|
|
How m i going to unit testing this kind of function?
plz help.
private void saverecord()
{
OleDbConnection savecon = new OleDbConnection(constring);
OleDbCommand savecom = new OleDbCommand("insert into Employee_Details values (?,?,?)", savecon);
OleDbParameter param;
param = savecom.Parameters.Add("@empcode", OleDbType.VarChar, 10);
param.Value = txtcode.Text;
param = savecom.Parameters.Add("@empname", OleDbType.VarChar, 25);
param.Value = txtname.Text;
param = savecom.Parameters.Add("@empjoin", OleDbType.Date);
param.Value = DateTime.Now.ToShortDateString();
savecon.Open();
int rows = savecom.ExecuteNonQuery();
MessageBox.Show(rows.ToString() + "rows affected");
btnref.PerformClick();
savecon.Close();
}
[TestMethod()]
public void saverecordTest()
{
Form1_Accessor target = new Form1_Accessor(); // TODO: Initialize to an appropriate value
target.saverecord();
//Assert.Inconclusive("A method that does not return a value cannot be verified.");
}
|
|
|
|
|
Best way would be to seperate your GUI (form) from your dataaccess. This will give you the opportunity to test GUI and data-access seperately.
For GUI testing use mocks to simulate the data-access. Testing the data-access is simple, just call your saveRecord-Method and try to read the record afterwards (don't forget to cleanup afterwards).
Regards
Sebastian
|
|
|
|
|
okay..another question,is it necessary to use assert? when shuold we use assert and when not?
for example,how to insert the assert to verify the result?
[TestMethod()]
public void saverecordTest()
{
Form1_Accessor target = new Form1_Accessor(); // TODO: Initialize to an appropriate value
target.txtcode.Text = "19095";
target.txtname.Text = "453427";
target.txtaddress.Text = "s34235";
target.saverecord();
}
|
|
|
|
|
Well using assert is necessary. What you want to test is whether your saveRecord()-method works correct. What if the method has a bug and txtcode and txtname are interchanged. You won't get an exception, so you will need an Assert. (Whenever you don't get an exception, use Assert !)
After saving the record you have to read the values which were stored. Use the Assert-statement to check if the values are stored correctly.
...
target.saverecord();
Assert.IsTrue(...Equals("19095"));
As I said before, I suggest to refactor your code so that you have a datalayer and a GUI. This will make unit testing easier. Also take a quick look into the NUnit-Quickstart documentation. They provide a well-known example.
Regards
Sebastian
|
|
|
|
|
Hello,can someone instruct me how to capture network video stream.I want to capture video stream from msn messenger,until now I have found several frameworks,but didn't find how to capture video from msn over network to my HDD.Thx
Servia Nostrum Regnum
|
|
|
|
|
Anyone?
Servia Nostrum Regnum
|
|
|
|
|
Hello Friends,
I need your help regarding the socket programming . Let say i am in the server system . Client has send a xml file using TCP to a specific port . My problem when i read data using NetworkStream then then it has been stopped there not able to find it out where is the problem , even it does not through any error .
But when i send and receive data to the same system ( mean to say the server and client is same ) then its working fine . I am able to receive data . But when server and client is different then the problem occurs . I am puuting the sample code . Please look into the code and help me if you people have any idea .
TcpClient c = new TcpClient("Test", 1027);
NetworkStream ns = c.GetStream(); // get stream
byte[] buf = new byte[8024]; // create byte array to receive data
ns.Read(buf, 0, 8020); // read data from stream into byte array
// read data from stream into byte array
string st = System.Text.Encoding.ASCII.GetString(buf); // convert byte array to string
// create a writer and open the file
TextWriter tw = new StreamWriter("D:\\test.txt");
// write a line of text to the file
tw.WriteLine(st.ToString());
// close the stream
tw.Close();
c.Close();
Console.WriteLine(st);
|
|
|
|
|
i want to save gridview values in database. here some fields are fetched from one table that fields are empname empid empphoneno and remaining fields are time and attendence. i used radio button list for attendence column. the list is present, obsent and leave. the selected value and remaining fields are save in another table plz give me solution i am using sql 2005 and c#
|
|
|
|
|
anybody give me code for this
|
|
|
|
|
protected void btnSave_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
try
{
foreach (GridViewRow gvr in gvWorkGroup.Rows)
{
new StockInformation_FK().SaveItemes(txtItemId.Text, ddlCatagoryName.SelectedValue, ddlSupplierName.SelectedValue, ddlBrand.SelectedValue, txtItemName.Text, txtPartNo.Text, txtSerialNo.Text, ddlStatus.SelectedValue, txtPrice.Text, dtPurchase.Text, dtWarranty.Text, txtInvoiceNo.Text, txtRemarks.Text, "");
}
ShowSuccesMessage(LoadSucessMsg());
ClearAll();
LoadGrid();
}
catch (Exception ex)
{
throw ex;
}
}
}
modified on Thursday, September 15, 2011 5:43 AM
|
|
|
|
|
Is there any way to find which all .lib, .dll etc files are included in a exe ?
or
Is there any way to find which all .lib, .dll etc files are included in a .lib ?
RKP
|
|
|
|
|
I used dumpbin.exe but its not verbose.
RKP
|
|
|
|
|
When a PDF file gets downloaded in temporary Internet files while it is opened on browser.
How can I get the time taken for PDF getting downloaded.
upto this, the main should be stopped until PDF file gets fully downloaded. How to fix it?
|
|
|
|
|
Not sure what you mean by 'the main should be stopped' but you probably want to ask in the ASP .Net forum (as this isn't really a C# question)
I'd guess, though, that you'd have to write some javascript to trigger from the client when downloading is complete - and my guess would be that this might be very client dependent.
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
Hi,
I created a simple C# program that imports a dll (Unmanaged dll), which a coworker wrote, the dll references other managed dll's (kernel32.dll,...etc) . On the PC i built the app on everything works great ( /bin/Debug/test.exe Folder), as well the unmanaged dll resides in the same folder as the .exe.
I published the app and ran it on another PC and i receive an error " Unable to load DLL "DSVR.dll" ..." Details
************** Exception Text **************
System.DllNotFoundException: Unable to load DLL 'DSVR.dll': This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem. (Exception from HRESULT: 0x800736B1)
at DSVR_CSharpExample.DSVR.DSVR_Open()
at DSVR_CSharpExample.Form1.Form1_Load(Object sender, EventArgs e) in C:\Program Files\H&E\DSVR_CSharpExample\Form1.cs:line 127
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
I installed the same version of .net, Redistribution 2008 SP1, Powerpacks, etc.. i ran dependency walker and everything traced out fine.
Any Suggestion on What am i doing wrong (I've been trying to figure this out for 2 days) ?
Namespace DSVR_CSharpExample
{
public static class DSVR
{
[DllImport("DSVR.dll", EntryPoint = "DSVR_Open")]
public static extern IntPtr DSVR_Open();
[DllImport("DSVR.dll", EntryPoint = "DSVR_Close")]
public static extern void DSVR_Close(IntPtr ConnectionHandle);
.
.
.
.
Much appreciated,
Matt
|
|
|
|
|
Hi Matt,
the unmanaged DLL might need other unmanaged DLLs and be unable to find them; that would result in the error message you are getting (it is regrettable the message Windows provides isn't more specific).
Two likely causes:
1. those DLLs are simply not present (e.g. debug versions of the C run-time library, part of Visual Studio, and not present on other PCs). The easiest solution then is to release-build the native app.
2. those DLLs are present but the folder that contains them is not part of your PATH environment variable. If so, fix the PATH.
|
|
|
|
|
Hi Luc, thanks for the response.
All the DLL's are present (according to dependency walker). I've updated the PATh environment variable and the same issue is happening. As a test i installed VS 2008 on the client PC and the app runs (If finds all the dlls), i have a strong feeling it's some sort of pathing issue, does that seem right? (I can't leave VS on the client machine).
-md
|
|
|
|