Git Product home page Git Product logo

Comments (2)

jonpryor avatar jonpryor commented on August 15, 2024

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:

  1. 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.

  1. I have create c++ dynamic library(.dll)
  2. I write the function to sign the strings using private key by openssl.
  3. I can call it in .net Console Application in Windows.
  4. now How can I call it in .net android? or how to make it to .so file?

You would need to:

  1. 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.

  2. Use the Android NDK to compile your C++ code into a libexample-name.so, and have libexample-name.so link against your libssl.so.

  3. Ensure that libexample-name.so has an extern "C" function, e.g.

    extern "C" void DoTheSigningThing(void* parameter);
  4. You would add both libexample-name.so and libssl.so to your .NET for Android app into an appropriately named directory, e.g. lib\arm64-v8a\libexample-name.so.

  5. 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.

ljzj2 avatar ljzj2 commented on August 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.