|
yeah i think you should i would deffinitly like to read it.
The Code Project Is Your Friend...
|
|
|
|
|
I'm looking at writing an app for storing passwords for the different mailing lists i'm on, with the data encrypted and stored in an xml file. I was wondering if there is a way (in c#) to get a password from a user, and use that as the key to decrypt the data.
I've looked (briefly) through the System.Security.Cryptography namespace but it seems to mostly deal with keys (seperate files), but I would much prefer to input a password and use that as the decryption key - is this possible?
|
|
|
|
|
this is what i use in my program to encrypt hole files. you can possibly use it for yours as well;
inName = full path of the file to be encrypted(this file is only opened and not deleted...you will have to rewrite that part)
outName : output...encrypted file
KeySecretString (the password to encrypt with)
to decrypt the file use the same code but replace :
CryptoStream encStream = new CryptoStream(fout, tdes.CreateEncryptor(tdes.Key, tdes.IV), CryptoStreamMode.Write);
with :
CryptoStream encStream = new CryptoStream(fout, tdes.CreateDecryptor(tdes.Key, tdes.IV), CryptoStreamMode.Write);
further more where you see the code DESCryptoServiceProvider des = new DESCryptoServiceProvider(); you can replace the DES part with RC2 to get RC2 encryption / decryption instead.
Happy Coding...
Jesse M
<br />
private void DecryptData(String inName, String outName, string KeySecretString)<br />
{ <br />
FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read);<br />
FileStream fout = new FileStream(outName, FileMode.OpenOrCreate, FileAccess.Write);<br />
fout.SetLength(0);<br />
string FileN = Path.GetFileName(outName);<br />
InformationFile.Text = FileN;<br />
InformationFile.Update();<br />
byte[] bin = new byte[buffersize];
long rdlen = 0;
long totlen = fin.Length;
int len;
DESCryptoServiceProvider tdes = new DESCryptoServiceProvider(); <br />
tdes.IV = ASCIIEncoding.ASCII.GetBytes(KeySecretString); <br />
tdes.Key =ASCIIEncoding.ASCII.GetBytes(KeySecretString);<br />
CryptoStream encStream = new CryptoStream(fout, tdes.CreateDecryptor(tdes.Key, tdes.IV), CryptoStreamMode.Write); <br />
Console.WriteLine("Encrypting...");<br />
while(rdlen < totlen)<br />
{<br />
len = fin.Read(bin, 0, buffersize);<br />
encStream.Write(bin, 0, len);<br />
rdlen = rdlen + len;<br />
Console.WriteLine("{0} bytes processed", rdlen);<br />
<br />
}<br />
fout.Flush();<br />
fin.Flush();<br />
encStream.Flush();<br />
encStream.Close();<br />
fout.Close();<br />
fin.Close();<br />
return;<br />
} <br />
The Code Project Is Your Friend...
|
|
|
|
|
The code looks interesting, I might be able to modify it to what I want. Instead of encrypting the whole file though, all I want to do is encrypt the data in the xml file.
|
|
|
|
|
im not gonna post the code agian...but the code utilized a file stream(inName)....you can save the xml file then encrypt it..but the problem is..for the millisecond that the file is saved on the hd and encryption hasnt got to it it is open. but you might beable to swap the FileStream with the XMLWriter (cant remeber the exsact name for it) try it..and the encryption stream might work fine with a xml stream ..... happy coding.
Jesse M
The Code Project Is Your Friend...
|
|
|
|
|
Thanks fror your help - in this instance security isn't that high a priority - I'm only writing this for myself as an experiment
|
|
|
|
|
This is something I see implemented incorrectly time and time again. The *correct* way to derive a key from a string password is using the System.Security.Cryptography.PasswordDeriveBytes method - it's usage is very straight forward.
|
|
|
|
|
Hello all -
I'm trying to write some code to read ID3 tags from mp3 files. ID3 stores information at *the end* of the mp3 file in 128 bytes.
I want to avoid having to loop through the entire file to get the data that I need but it appears that one only can read from the beginning of a file using the .NET I/O classes.
Is it possible to call a version of a Read method with an offset specifying where in a file you want to start reading into a byte array?
eg:
string path = "c:\\downers\\Mancini.mp3";
FileInfo fi = new FileInfo(path);
// the file length
long len = fi.Length;
// subtract 128
long start= len - 128;
int st = (int)start;
Stream fis = File.Open(path,FileMode.Open, FileAccess.Read);
BinaryReader re = new BinaryReader(fis);
byte[] data = new byte[128];
re.Read(data, start, 128); // this won't work, but you get my intuitions...
This doesn't work though; the offset argument in the middle of the read method is an offset in the byte array to start on.
Any ideas? Am I missing something obvious? Otherwise I just have code that loops through the entire file a byte at a time.
*->>Always working on my game, teach me
*->>something new.
cout << "dav1d\n";
|
|
|
|
|
FileStream Mp3Stream = new FileStream(mp3File, FileMode.Open, FileAccess.Read);
Mp3Stream.Seek(-128, SeekOrigin.End);
|
|
|
|
|
Why is your code so long? Remember you can do most things with few lines of code.
You probably want something like this.
FileStream f = File.OpenRead("x");
f.Seek(-128, SeekOrigin.End);
f.Read(bytearray, 0, 128);
f.Close();
Also, you can get the length of the file just with f.Length;
Forget about using BinaryReader, David; it's for smart people. It allows you read/write different types like doubles, integers instead of working with bytes.
Thanks,
Wes
|
|
|
|
|
Thanks Wes,
very helpful. I 'discovered' seek a few minutes after posting
My code was a bit more lengthy because I was still feeling my way around the problem. Like usual, I should have cleaned up a bit before posting...
*->>Always working on my game, teach me
*->>something new.
cout << "dav1d\n";
|
|
|
|
|
ID3V1 tag reading / writing has been done many times over in C# - a quick google search could save you a lot of time.
|
|
|
|
|
Are there any other methods to do printing in .net other than crystal reports and printdocument objects.
I want to print on non-standard papers,but did not find a better solution.
Thanks.
this is my signature for forums quoted from shog*9:
I can't help but feel, somewhere deep within that withered, bitter, scheming person, there is a small child, frightened, looking a way out.
|
|
|
|
|
What's the difference (if any) between:
[MethodImpl(MethodImplOptions.Synchronized)]
void SomeMethod()
{
}
and
void SomeMethod()
{
lock(this)
{
}
}
?
|
|
|
|
|
I don't believe there is any difference.
This is how lock is implemented.
object tmp = this;
Monitor.Enter(tmp);
try
{
DoSomething();
}
finally
{
Monitor.Exit(tmp);
}
For static methods, the class type is used instead of this.
From the specification, synchronized works the same as using lock(this) and lock(typeof(Class)) for statics around the method. I think both actually used the syncblockindex that every object has, so that mixed use will probably work correctly as well.
But in one Microsoft article on performance, it was suggested that synchronized function calls are faster than using locks. I think the reasoning used was that fine-grained locks are less performant--the higher-up the synchronization, the less overhead incurred because of fewer traffic lights.
My guess is that the implementation is actually the same.
|
|
|
|
|
I have tried several different ways to use this DLL, but can not get it to work. I have registered the DLL via regsvr32.
En/Decode MIME-Content with MimeSniffer
http://www.codeproject.com/internet/mimesniffer.asp?df=100&forumid=3772&noise=1&app=50&fr=51
The author only provides VB code for it and that does not help me much.
|
|
|
|
|
In the menu: Project->Add Reference, in here you select the COM Tab and select MimeSniffer.
Then it's just something like
MimeSnifferLib.Client ms = new MimeSnifferLib.Client();<br />
ms.CallAFunction();
I have not used MimeSniffer, so Client is probably called something else, but I hope you get the point...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Academic project. Free download from http://www.doteasy.addr.com
Abstract: "dotEASY" is a Visual Studio .Net Add-in that evaluates C# source code and performs "advices" in order to improve software quality. The configuration and programming of the "advices" is invisible to the developer, the tool’s final user, who only requests for code evaluation. A new "advice" can be created defining metrics, thresholds and optionally programming validation classes and execution classes to automatically modify the code. The export and import capabilities allow one person to create an "advice", which can be configured and exported, so it can be used by many other people.
Regards,
Juan Esteban Suárez
|
|
|
|
|
How to Click a Button in Another Application Programatically in C#?
|
|
|
|
|
Have you tried to raise the click event of the button?
But I'm not sure about crossing process threads, maybe use a Mutex.
R.Bischoff | C++
.NET, Kommst du mit?
|
|
|
|
|
I would like to write a simple syntax highlighter for one of my c# applications but i cant seem to find any examples on how to do this. My current plans are to use a richtextbox and somehow do the highlighting in this but i cant find any examples of how to use a richtextbox for something similar.
Does anyone know of any c# examples of syntax highlighters or if not any code snippets that might help me in writing one?
Thanks
Tim
|
|
|
|
|
|
I do have sharp develop but i was hoping for a much more simplistic view of it, i dont need it to do overly much at the minute but, i was hoping for something a lot less integrated and basic overview of how to do it.
Thanks all the same though
|
|
|
|
|
C#
Is it possible to declare reference variable?
I wanna change member variable of TextHandler class from Mouse class Basically I wanna keep reference to the member of another class).
public class Mouse<br />
{<br />
<br />
protected string strRefText;<br />
<br />
public Mouse(ref string strInText)<br />
{<br />
<font color=blue>this.strRefText = strInText;</font><br />
}<br />
<br />
public void AddMouse()<br />
{<br />
strRefText += "I'm mouse.";<br />
}<br />
}<br />
<br />
<br />
public class TextHandler<br />
{<br />
protected string strText;<br />
<br />
public void Main()<br />
{<br />
strText = "I'm dog. ";<br />
Mouse myMouse = new Mouse(ref strText);<br />
myMouse.AddMouse();<br />
Console.Write(myText);<br />
}<br />
}
|
|
|
|
|
Thomas W wrote:
// Add mouse text
public void Main()
{
strText = "I'm dog. ";
Mouse myMouse = new Mouse(ref strText);
myMouse.AddMouse();
Console.Write(myText);
}
Where is myText declared?
R.Bischoff | C++
.NET, Kommst du mit?
|
|
|
|