Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Generate digital signature from a string

  1. #1
    Junior Member
    Join Date
    Sep 2018
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Generate digital signature from a string

    Hi all,

    I have a private key file (.pem) and a self-signed certificate file (.pem). I need to sign a string using both files, how can I do this? till now I can generate a digital signature using the private key but it's not working. How to use the certificate file in this case? knowing that the format of the signed data should be PKCS#7

    Thanks in advance,
    Joud

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Generate digital signature from a string

    Can you post the code you are having problems with and describe what the problem is?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2018
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Generate digital signature from a string

    It's really long and complicated. Let me rephrase the question:
    - I, the client, have generated a self-signed certificate with private key using openssl.
    - The certificate has been imported to the server to which I need to do http Get and Post requests (which will be signed - with a signature parameter passed) - and the certificate will be used to verify the signature.
    - I generated the signature from a message using the private key.

    My question is, do I need to use the certificate from my side for generating the digital signature? or the private key is enough? How the server will recognize what certificate to use for verification? This is the first time I work with certificates.

    Here's the simple code I use:

    String message = 'some message'
    //Load the private key from pem file
    PrivateKey privateKey = loadPrivateKey()
    //Sign the message
    Signature signature = Signature.getInstance("SHA256withRSA")
    signature.initSign(privateKey);
    signature.update(message.getBytes());
    byte[] signedMsg = signature.sign();

    Thanks in advance
    Last edited by Joud; September 12th, 2018 at 09:59 AM.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Generate digital signature from a string

    Sorry, I don't know anything about servers and certificates.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Digital Persona Finger Print Java Applet
    By luqman in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 21st, 2014, 02:12 PM
  2. Reading electrical digital signal through java
    By Subhajit Banerjee in forum Java Networking
    Replies: 2
    Last Post: July 6th, 2013, 08:20 PM
  3. Digital Life Assistance system using JAVA
    By himvais in forum The Cafe
    Replies: 1
    Last Post: August 24th, 2012, 02:12 PM
  4. Digital Signage Player
    By staradder in forum Java Theory & Questions
    Replies: 9
    Last Post: October 4th, 2011, 05:29 AM
  5. Digital Watch program and Sorting arrays
    By c.P.u1 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: February 5th, 2011, 05:21 PM

Tags for this Thread