|
MSDN has several good samples. Here is one.
using System;
using System.Security.Cryptography;
using System.Text;
class RSACSPSample
{
static void Main()
{
try
{
UnicodeEncoding ByteConverter = new UnicodeEncoding();
byte[] dataToEncrypt = ByteConverter.GetBytes("Data to Encrypt");
byte[] encryptedData;
byte[] decryptedData;
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
encryptedData = RSAEncrypt(dataToEncrypt,RSA.ExportParameters(false), false);
decryptedData = RSADecrypt(encryptedData,RSA.ExportParameters(true), false);
Console.WriteLine("Decrypted plaintext: {0}", ByteConverter.GetString(decryptedData));
}
catch(ArgumentNullException)
{
Console.WriteLine("Encryption failed.");
}
}
static public byte[] RSAEncrypt(byte[] DataToEncrypt, RSAParameters RSAKeyInfo, bool DoOAEPPadding)
{
try
{
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
RSA.ImportParameters(RSAKeyInfo);
return RSA.Encrypt(DataToEncrypt, DoOAEPPadding);
}
catch(CryptographicException e)
{
Console.WriteLine(e.Message);
return null;
}
}
static public byte[] RSADecrypt(byte[] DataToDecrypt, RSAParameters RSAKeyInfo,bool DoOAEPPadding)
{
try
{
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
RSA.ImportParameters(RSAKeyInfo);
return RSA.Decrypt(DataToDecrypt, DoOAEPPadding);
}
catch(CryptographicException e)
{
Console.WriteLine(e.ToString());
return null;
}
}
}
Farhan Noor Qureshi
|
|
|
|
|
i have added control at runtime in .aspx page using c#. the dyamic controls are textbox and literal controls. as per the design issue i have added all thes controls in a html table in which i have added dynamic rows as per requirement. so table > dyamic row>panel>table with the controls.
so now i cant find the controls as the dynamic child level is three...
Please help me out...
Thanx..
Jayesh Talsaniya
|
|
|
|
|
Why would you have to find the controls? Just keep the references from when you create the controls.
---
single minded; short sighted; long gone;
|
|
|
|
|
When you create a control dynamically, assign it a unique name. Now when you need to refer to them you can call something like this:
FindControl("<your unique control name level 1>").FindControl("<your unique control name level 2>").FindControl("<your unique control name level 3>")
Farhan Noor Qureshi
|
|
|
|
|
Q #1:
I have two buttons to zoom in and zoom out the text size of a RichTextBox. Is it possible to increment/decrement the ZoomFactor by 0.1F each time?
Q #2:
Does changing the ZoomFactor also change the font size when you save the file as .rtf?
Thanks,
Mark
|
|
|
|
|
Hi,
Q1.
from reading the documentation it is not completely clear, so an experiment may be in order.
It says it accepts numbers from 1/64 to 64
That could mean all fractions 1/n and all integers n with 1 <= n <= 64
Q2.
I doubt that very much; normally "zoom" indicates a visualization property, not a
content property. Try it !
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Thanks for the tips. I will have to make a small test form and see what happens.
Mark
|
|
|
|
|
Yes it is Possible
No it does not any effect on the saved File
|
|
|
|
|
Is there a way to have the text expand to the left (locking the right) of a label?
|
|
|
|
|
Sure, give it the Width you want, turn AutoSize off, and set TextAlign to one
of the Right values.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
|
If you haven't seen the Django web app framework, it's pretty cool.
All DB access code is generated dynamicly -- all you have to do is define the table structures you want. I.E. (python code)
class Person(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
Which Django would evaluate to:
CREATE TABLE myapp_person (
"id" serial NOT NULL PRIMARY KEY,
"first_name" varchar(30) NOT NULL,
"last_name" varchar(30) NOT NULL
);
To create a new row in the person table, just create a new instance of Person and call save()
p = Person(first_name='Alex', last_name='Egg')
p.save()
To get all the rows/fields from the Person table just call the static method all Persons.objects.all()
It all seems so elegant, so I wanted to try and recreate this using C#.
So I created a class called Model which is a DB Model like the person class above. I also created a Manager class which exposes the static method All to read data.
public class Model
{
public Model()
{
new NotImplementedException();
}
public static Manager Objects;
public void Save()
{
}
public void Delete()
{
}
}
public class Manager
{
public Manager()
{
}
public void Get()
{
new NotImplementedException();
}
public void All()
{
new NotImplementedException();
}
}
So now I will create my Person object in C#:
public class SentRecord : Model
{
public Person(string firstName, string lastName)
{
this.FirstName= firstName;
this.LastName = lastName;
}
public string FirstName;
public string LastName;
}
I figure this this is pretty much the same idea as the python Person class at the top.
Now I create a new instance of my Person model:
Person p=new Person("Alex","Egg");
Now I can save it to the DB by calling:
p.Save();
Now, my question is, how do I go about implementing Model.Save()? I somehow need to get the names of deriving class' public fields. Reflection? So If I just get the table name (I'll hardcode for now) and the People's fields I can generate my SQL insert statement.
Any pointers on how to implement Save()?
/\ |_ E X E GG
|
|
|
|
|
Theres 101 data access layers out there, go do some googling and you'll find plenty including tutorials on how to make your own.
|
|
|
|
|
eggie5 wrote: I somehow need to get the names of deriving class' public fields. Reflection?
Yep, reflection would be the way to get the data. Custom attributes would come in handy too:
class Person
{
[Column("AgeColumn")]
public int Age;
}
Where TableFieldName is a custom attribute. Those may come in handy to get the corresponding table or column for a class or field.
As the other poster noted, there are a lot of data access layers out there that do this. In the upcoming .NET 3.5, you'll have built-in support for this in the form of LINQ (language integrated query), and it's extension of LINQ-to-SQL and other databases. See Scott Guthrie's blog post on LINQ to SQL[^] for more info.
|
|
|
|
|
I have a class: classA
classA starts a new thread: threadA
threadA fires an event.
My classB has a listener to this event.
When threadA fires the event I want to run a method in classB.
However, myMethod() will run it on the threadA thread and I want it to run on the main thread (like the rest of the classB class, and the variables etc)!
I'm using the compact framework
Do you know of a way to switch to the main thread to execute the method? Will I need to create an invoker? This seems more for windows forms..
I hope I’ve explained it well enough and you can make some sense of it!
any help is greatly appreciated.
|
|
|
|
|
Best way to do this is have your main thread watch a queue of functions, e.g. delegates to execute. When your background thread needs to have a function execute on the main thread, enqueue that function into the main thread queue of pending actions. When a new function is enqueued, have the main thread execute it.
This is essentially how calling control.Invoke and .BeginInvoke works in WindowsForms: you're essentially posting a message to the UI thread message queue, telling it to execute some delegate.
|
|
|
|
|
Hey guys,
I have been toying around with the idea of writing a website creation program geared to novice computer users. I have googled it and I can't find anything helpful in regards to how to structure the program or writing code generation. Can anybody point me in the right direction?
may your code be error free
|
|
|
|
|
There are 3 parts:
1. Input
2. Processing
3. Output
Seeing you have some form of input and you desire some form of output, the implement step 2. 90% of applications use this 'data transformation'. There is no magic involved.
|
|
|
|
|
Hi,
This is just off the top of my head as I haven't done any web work for years, but depending on exactly how much functionality you wish to offer and what code you wish to generate, you should look at .NET CodeDOM for code generation and the use of XSLT with XML. XSLT can convert XML to HTML or XHTML markup, but it can also be used to generate C#, javascript or any other language from XML. If you got the users to make selections via your UI then stored these as XML you could easily generate code thus. I'm sorry not to provide more detail, but I think this is at least the right direction.
Regards,
Toby
|
|
|
|
|
Thanks a million Toby for the heads up. That's the most info i've got so far. I'll definitly take a look at it and if you have anymore info, I'd be happy to hear it!
Thanks again,
Richard
may your code be error free
|
|
|
|
|
how can I convert a char arrayto a string?
i used method ToString() but it dosn'twork .
|
|
|
|
|
One of the constructors for a string takes a char[].
|
|
|
|
|
you can try:
string s = new string(mycharArray);
|
|
|
|
|
For generic purpose type converting there's a static class "Convert". There you have a "ToString([param])" method
Visit my blog at http://dotnetforeveryone.blogspot.com/
|
|
|
|
|
I think the best way to do that is to use a generic list
List<char> chars = new List<char>();
chars.Add('t');
Console.WriteLine(chars[0].ToString());
Lester
http://www.lestersconyers.com
|
|
|
|