|
hi
in c# i used
Convert.ToBase64String(Encoding.ASCII.GetBytes(my_str))
and in js i used the base64 encoding i found in amongst the encryption files from http://labs.boulevart.be/index.php/2007/05/23/encryption-in-as2-and-as3/[^] which is where my problems began.... not that i'm putting down what they have there, I just couldn't get it to produce the same results from my end with the rijndael/TEa encryption, the base64 seems to be fine
tim
edit:
this is the function that encodes to base64 in js:
*/
private static var base64chars:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
public static function encode(src:String):String {
var i:Number = 0;
var output:String = new String("");
var chr1:Number, chr2:Number, chr3:Number;
var enc1:Number, enc2:Number, enc3:Number, enc4:Number;
while (i < src.length) {
chr1 = src.charCodeAt(i++);
chr2 = src.charCodeAt(i++);
chr3 = src.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if(isNaN(chr2)) enc3 = enc4 = 64;
else if(isNaN(chr3)) enc4 = 64;
output += base64chars.charAt(enc1)+base64chars.charAt(enc2);
output += base64chars.charAt(enc3)+base64chars.charAt(enc4)
}
return output;
}
|
|
|
|
|
tim_gunning wrote: in c# i used
Convert.ToBase64String(Encoding.ASCII.GetBytes(my_str))
The ASCII encoding only handles characters with character code 0 to 127. To get the equivalent of the JScript code you would have to loop through the string and get the character codes into a byte array, so that you get the characters with character codes from 0 to 255.
The JScript code claims to encode a string to base64, but that it not really possible. It assumes that there are never any character codes above 255. If there is, the result will be incorrect.
To correctly turn a string into base64, you first have to encode it using an encoding that can handle the full unicode character set, like UTF-8:
Convert.ToBase64String(Encoding.UTF8.GetBytes(my_str))
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
hi
originally I wss using UTF8 but the js wasnt coping and then I realised chars were missing from the c# end (anything over 127 or so) which I needed (long story....;p) anyway to cut it short I've encoded the js to UTF8 and the c# and then both to base64, used StringBuilder to create my return string and both the js in the flash and c# are producing identical results which is what I needed, I'll post it up here at some point as it may be of interest to someone.
thanks for all your help/pointers guffa, very much appreciated.
tim
|
|
|
|
|
Guffa wrote: To create a 100 character string, you will have created 10 kB of strings. To create a 1000 character string, you will have created 1 MB of strings.
Great ! I am curious to know how you calculated this ?
|
|
|
|
|
You just add the length of the strings, and multiply by two (as each character is two bytes).
(1+2+3+4+...+98+98+99+100) * 2 = (101 * 50) * 2 = 10100
(1+2+3+4+...+998+999+1000) * 2 = (1001 * 500) * 2 = 1001000
The actual amount of memory used is slightly more, as there is some overhead in each object.
Despite everything, the person most likely to be fooling you next is yourself.
modified on Sunday, July 6, 2008 9:25 AM
|
|
|
|
|
Thanks.
|
|
|
|
|
Hi,
I have created a windows service which looks at an xml file to get data.
The xml file gets modified using a windows application.
If the xml file is changed then the service has to be uninstalled and then installed again so that the service picks up the new xml file data, otherwise the service looks at the old xml data.
Question:
How can I avoid the manual interaction with the visual studios command where at present I use it to uninstall and install the service? Can I make the windows application to do the un/install everytime there is a change in the xml file?
Thanks
|
|
|
|
|
Iy shouldn't be nessecary to reinstall every time the xml changes.
You could add a FileSystemWatcher to monitor changes in the xml-file and make the service load the updated xml-file.
|
|
|
|
|
Your design is wrong. You have to use a FileSystemWatcher , handle it's event and load the XML file when it changes.
|
|
|
|
|
I'm building a Windows Installer project using Visual Studio. I've got it set where the app data is installed in the AllUsers folder if the users clicks the "Everyone" radiobutton.
My problem is that when I switch to a non-administrative account, I can start the app but as soon as the program tries to access the AllUsers folder, an "Access denied" exception is thrown! What am I doing wrong?
I've read articles that say your app will be vista compatible if an non-administrative user can access it in XP. (which is what I'm using)
Happy 4th!
Richard
"Make it as simple as possible, but no simpler" Issac Newton
|
|
|
|
|
In the Windows security model, a non-administrative user is not (or at least should not) be able do anything affecting other users.
You can only read from the AllUsers folder. All settings should be stored in a per-user folder, not in your program's installation folder.
|
|
|
|
|
Thanks for the reply. That does shed some light into my problem. However, I am still confused. One of the program features involves writing to a central log when a record is viewed. This log needs to visible for all users. What directory is safe for all types of users?
"Make it as simple as possible, but no simpler" Issac Newton
|
|
|
|
|
Can anybody share some knowldge on how to detect un used regisrty key from a system nd deleting those unused keys.
regards,
|
|
|
|
|
There is no way to tell if a registry key may be used in the future or not.
Don't go deleting registry keys you think might no be in use, you'll only screw things up.
If you want to clean up your registry, go get a tool like CCleaner.
(I once read some good advice regarding the registry. It went something like this. "If you have to be told how to use the registry, you shouldn't be using it." )
Simon
|
|
|
|
|
Delete them, if windows or a program breaks, they were not unused. Sorry, that really is the best advice possible.
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
hello,
m working on win forms using C#.net i use Appupdater to update version. My application gets updated but the application doesnt restart. When i manually start the application it starts with new version. How do i relaunch my application after Updation?
|
|
|
|
|
|
in C#.net 1.1 i dnt have Application.Restart();
|
|
|
|
|
Wow, never seen that one before You learn something new everyday, thanks
|
|
|
|
|
leppie wrote: Wow, never seen that one before
do you really mean it ?
|
|
|
|
|
N a v a n e e t h wrote: do you really mean it ?
Yes, no joke. I have never needed that
|
|
|
|
|
Ohh then I am delighted that I could able to help you. Thanks.
|
|
|
|
|
|
<pre> I am trying to access a C DLL from C# .The problem i am facing when i pass a structure to the C dll function .I am passing the structure by out Keyword.here is the code
--------------------------------------------------OneStruct .dll----------------------------------------------------------------
#include<iostream.h>
#include<conio.h>
#include<malloc.h>
#include<string.h>
extern "C"
{
typedef struct
{
unsigned long * var1;
float * var2;
}Esp;
typedef struct
{
char * var3;
char * var4;
}Real;
__declspec(dllexport) void GetValue(Esp * villa,Real * rud) //when function gets called i added the watch on villa and it shows me that CXX0017:Error:Symbol 'villa' not found
{
rud->var3 = (char*)malloc(50);
memset(rud->var3, 0x00, 50);
rud->var4= (char*)malloc(50);
memset(rud->var4, 0x00, 50);
strcpy(rud->var3, "robhino");
strcpy(rud->var4,"zidane");
unsigned long a=9999;
villa->var1=&a;
float b=15.6f;
villa->var2=&b;
}
}
--------------------------------------------------------------------------------------------------------------------------------
----------------------------------HandleOneStruct----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace HandleOneStruct
{
[StructLayout(LayoutKind.Sequential)]
public struct Esp
{
public IntPtr var1;
public IntPtr var2;
}
[StructLayout(LayoutKind.Sequential)]
public struct Real
{
public string var3;
public string var4;
}
class LibWrap
{
[DllImport("OneStruct.dll")]
public static extern void GetValue(out Esp villa,out Real rud);
}
class Program
{
static void Main(string[] args)
{
Esp villa;
Real rud;
//villa.var1=Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof (Esp)));
//villa.var2 =Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(Esp)));
//villa.var1 = new IntPtr(11);
//villa.var2 = new IntPtr(19);
LibWrap.GetValue(out villa,out rud);
Console.WriteLine(rud.var3);
Console.WriteLine(rud.var4);
Console.Read();
}
}
}
---------------------------------------------------------------------------------
When i debugg this code i am getting value of rud structre variable as robhino zidane correctly but the value of villa structre varibale are 12345,12346(some address i guess).where as i want the value villa->var1=9999 and villa->var2=15.6f.i really don't know how to get the values of var1=9999 and var2=15.6f .can anyone guide me how to get the desired result.what i need to do to run this code successfully .Is there any other way to run this code please tell me.
Give me usefull link for this topic if possible ?One more thing if i want to intialize IntPtr varible with long value or long * then how can i do this?
Any help Appreciated.
Thanks in Advance.
</pre>
|
|
|
|
|
You need to Marshal the IntPtr to int or float.
|
|
|
|