Comments (2)
Why do you want to use MD5 anything? MD5 is broken:
On 31 December 2008, the CMU Software Engineering Institute concluded that MD5 was essentially "cryptographically broken and unsuitable for further use".
2008 is 16 years ago. It should only be used if you absolutely need compatibility with something that consumes MD5, and it would far better to replace all of that with something more recent. (For example, we used to use md5 to create Java package names for Java Callable Wrappers, not because we needed security, but because MD5 was convenient. We've since moved to CRC64 hashes, which aren't cryptographically secure, and we never needed that anyway…)
Assuming you still want/need to use MD5, we then hit the next major hurdle:
- I write the function to sign the strings using private key by openssl.
The hurdle being that OpenSSL is not part of the stable Android API. You can't write C++ code for Android which uses OpenSSL unless you plan on (possibly building and) redistributing OpenSSL yourself.
.NET for Android does not directly use OpenSSL. Instead, .NET uses JNI to lookup Java APIs for TLS-related functionality.
- I have create c++ dynamic library(.dll)
- I write the function to sign the strings using private key by openssl.
- I can call it in .net Console Application in Windows.
- now How can I call it in .net android? or how to make it to .so file?
You would need to:
-
Obtain a copy of OpenSSL compiled for your target Android ABI. Let's call this
libssl.so
for demonstration purposes.It should be noted that this step itself may be very difficult, and in turn require that any apps redistributing your
libssl.so
stay on top of any and all security CVEs for OpenSSL. There are metaphorical dragons in this step. -
Use the Android NDK to compile your C++ code into a
libexample-name.so
, and havelibexample-name.so
link against yourlibssl.so
. -
Ensure that
libexample-name.so
has anextern "C"
function, e.g.extern "C" void DoTheSigningThing(void* parameter);
-
You would add both
libexample-name.so
andlibssl.so
to your .NET for Android app into an appropriately named directory, e.g.lib\arm64-v8a\libexample-name.so
. -
You would add a
[DllImport]
somewhere in your C# .NET for Android app to invoke (3), and elsewhere invoke it:[DllImport("example-name")] static extern void DoTheSigningThing(IntPtr p);
Again, redistributing OpenSSL is dealing with metaphorical dragons.
You would likely be better served rewriting your existing C++ code to use C# and types in the System.Security namespaces.
from xamarin-android.
thank you for so detailed answer.I've learned a lot.
now many people still use md5 and I do not know why.
is not part of the stable Android API.
but I find that.
PKCS8EncodedKeySpec
and KeyFactory.GetInstance
and Signature.GetInstance("MD5withRSA")
will fit me.
and I always answer others question not that patient. you answer me so many for each sentence. I should learn from you.
from xamarin-android.
Related Issues (20)
- Stop using undocumented attribute trimming HOT 5
- ANR with MediaPlayer and AndroidEnableMarshalMethods
- Crash when upgrading MAUI to 8.0.61 HOT 3
- EndOfStreamException in dotnet-trace when tracing an Android app HOT 6
- DSO handling for like-named libraries is broken HOT 7
- Please update xamarin-android to consume zlib-ng from dotnet/runtime HOT 4
- Expand Java directory mapping message to support multiple directories
- [AndroidManifest.xml] Determine which attributes to expose in Mono.Android.
- Automatically scan `<ProjectReference>` projects for bound Java libraries
- [Android] native crash by lib64/libhwui.so HOT 3
- How to make buttons have rounded corners??? HOT 1
- https://aka.ms/xa5207 link is dead HOT 1
- Could not resolve SDK "Microsoft.NET.Runtime.MonoAOTCompiler.Task" HOT 16
- Build/publish fails when project has a `&` (ampersand) in it during AOT phase HOT 2
- [Android, 9.0 Preview 5] Release configuration build results in a malfunctioning app (Preview 5 debug and Preview 4 release configurations work fine). HOT 7
- Runtime crash with Hot Reload in `libmono-component-debugger.so` HOT 2
- Android 14 permission changes causes SecurityException crash even when following the guidelines HOT 2
- Updating to version 5.0.0.2612 yields warning "R8 : warning : Missing class androidx.appcompat.graphics.drawable.DrawableWrapper"
- Android Service does not start if process name is specified in Service attribute HOT 6
- UnauthorizedAccessExceptions are getting raised when building a blank MAUI app when using .NET 9.0 HOT 15
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xamarin-android.