简体   繁体   中英

Call javascript function (with args) from c#

I have a WCF Service and I want to pass a SHA1 hashed string as a result.

On the client side, I have a simple html page with javascript.

I have the code to make the SHA1 string in javascript and I want to use it for both client (dehash the message) and server (hash the message).

The server is in C#.

So, is it possible to call the SHA1 javascript function from C#?

This doesn't make sense for two reasons:

1) You can't really share code between C# and JS, these languages are created for completely different purposes and are not interoperable, unless you are willing to allow code generation mess (like in ASP .NET Web Forms). Still, this looks like abuse of DRY that hurts in the long run.

2) SHA1 is one-way algorithm, there is no way to de-hash an encoded string (not talking rainbow tables here). You're using a wrong tool for the job.

您可以在HTML页面上放置隐藏的控件,然后将哈希值放在该控件中,然后从C#访问该控件。

NO! But you can put the SHA1 result into an input and post it to server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM