Why won't my message signature verify

Can anyone help. I dont seem to be able to verify a signature that I have just created. I'm a Java and Crypto newbie so please take it easy on me! The code is as follows:
import java.nio.ByteBuffer;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.Signature;
public class EncryptionLesson  {
     public static void main(String[] args) throws Exception {
          ByteBuffer message = ByteBuffer.wrap("This is my message".getBytes());
          // Create key pair
          KeyPairGenerator kpg;
          kpg = KeyPairGenerator.getInstance("DSA");
          kpg.initialize(512);
          KeyPair pair = kpg.genKeyPair();
          // Sign a message
          Signature sig = Signature.getInstance("DSA");
          sig.initSign(pair.getPrivate());
          sig.update(message);
          ByteBuffer messageSignature = ByteBuffer.wrap(sig.sign());
          // Verify signature
          Signature vsig = Signature.getInstance("DSA");
          vsig.initVerify(pair.getPublic());
          vsig.update(message);
          if (vsig.verify(messageSignature.array())) {
               System.out.println("Signature Okay");
          } else {
               System.out.println("Signature NOT Okay");
}The result is alway "Signature NOT Okay". Please excuse the gratuitous use of ByteBuffer, I have just read JavaNIO and was sold on them.

sorry about mistaking the vaiables in the previous post. the proper main will look like this:
public static void main(String[] args) throws Exception {
          ByteBuffer message = ByteBuffer.wrap("This is my message".getBytes());
          // Create key pair
          KeyPairGenerator kpg;
          kpg = KeyPairGenerator.getInstance("DSA");
          kpg.initialize(512);
          KeyPair pair = kpg.genKeyPair();
          // Sign a message
          Signature sig = Signature.getInstance("SHA1withDSA");
          sig.initSign(pair.getPrivate());
          sig.update(message.array());
          ByteBuffer messageSignature = ByteBuffer.wrap(sig.sign());
          // Verify signature
          Signature vsig = Signature.getInstance("SHA1withDSA");
          vsig.initVerify(pair.getPublic());
          vsig.update(message.array());
          if (vsig.verify(messageSignature.array())) {
               System.out.println("Signature Okay");
          } else {
               System.out.println("Signature NOT Okay");
     }Futher to bring it to your notice, this is signing and verification and not encryption ;-) you might consider your class name!

Similar Messages

  • Why won't my message notifications come up?

    It's not showing I have any messages until I physically go into the message app and then it'll say I have a message. Why? How can I fix this so it'll notify me when I get a text.

    Hello bafficr,
    Thank you for using Apple Support Communities.
    For more information, take a look at:
    iOS: Understanding notifications
    http://support.apple.com/kb/ht3576
    If you're not receiving notifications for a specific app, try these steps:
    Verify that the app supports notifications.
    After installing an app or restoring a backup to a different iOS device, open the app to begin receiving notifications. If the app requires entering or logging in to an account, you will need to do this before receiving notifications.
    Check Settings > Notification Center to ensure that the app is configured for notifications. If notifications do not appear in the Notification Center, verify that the Notification Center setting for the app is enabled.
    Badges: An image or number appears on the application icon.
    Have a nice day,
    Mario

  • Why won't I message work from my macbook pro?

    I have been trying to get my I message to work from my mac and everytime I go to log in it says "The server encountered an error processing registration. Please try again later" .. it always used to work from my computer, and now it won't. Does anyone know why? and how to fix this? Thank you.

    Following thread could slove the problem:
    https://discussions.apple.com/message/22552150#22552150

  • Why won't Verizon Messages app work on phone with Wi-Fi only?

    I've successfully downloaded and installed the app from Google Play on a phone of mine that I only use wi-fi on.  There is no cellular service to this particular device.  It's set to airplane mode, with wi-fi on, essentially making it a 4.5 inch tablet, or like an android equivalent to an iPod touch.  When I start the app though, it displays the screen shown in the included screenshot, and won't let me connect to the service, despite the fact that a wi-fi connection is present.  I've seen that this is an issue that some others have had.  I have Verizon service with my main phone, I'm not sure why the app that supposedly lets you access your texts via wifi will only do that on tablets or phones with cell service.  Is there any way to get this working? Will there be any updates to allow the functionality that I'm looking for?  I've read that it was present at one time, so why the change?

    According to the Verizon website you are wrong.
    Verizon Messages - Verizon Wireless
    It states "
    Use Wi-Fi to send and receive messages on your smartphone, tablet, PC, Mac and web browser"
    I find personally that you are correct, is the website designed to mislead us? it is the same on the play store for google.
    The difference is not just in one place, it is everywhere it is advertised. So it was meant to work but to charge customers the function was removed is my understanding.

  • Why won't the messages stop?!?

    I was woken at 0331 this-morning by a message from Telstra telling me that I have used 50% of my data allowance. There was a second, identical message at 0430. A third message at 0526, at which stage I angrily logged in to my account and turned notifications off. Despite turning notifications off, the messages have continued to arrive on my phone; at 0557, 0635, 0720, and the latest at 0744. I'm getting really, really pissed-off now, Telstra, for two reasons: 1. Why the hell does your system send people messages at 3.30a.m.?  In what universe is that even possibly acceptable?  It's not an emergency, it's a data-usage notification, and it is unbelievably inconsiderate to be sending people messages like that in the middle of the bloody night. 2. Why the hell haven't the messages stopped since I turned off the notifications? I shall await a reply, and I do hope said reply is more helpful than the robo-script replies I got from Telstra's email contact a few weeks ago when I had the same problem of SMS notifications arriving in the middle of the night! Totally unsatisfactory, Telstra.

    Well I am not 100% sure how it works however let’s say you were using data last night and you went through 50%, 75% and then 100% of your data. 5 hours later in the middle of the night it sends you a 50% data usage message, 5 minutes after that it sends you a 75% usage message and so on and so forth. It’s not an ideal system because of the delay however I guess if you weren’t to get the messages people would be unhappy about that as well. The delay in the usage is the problem. 

  • Why won't my Mac HD verify/repair after erasing it.

    Basically I had a problem with the HD saying it needed to be erased because it couldn't be repaired. So I had erased the HD (on the fastest speed) and tried reinstalling OS X mav but after 6 hours of installing I got a error message saying The HD needs to be repaired. I then tried verifying/repairing the HD and it said once again it needed to be erased. I have done this process a few times and the HD still shows it needs to be erased even though it has nothing on it.
    Am I missing a step or is my HD just dead?
    Any help is greatly appreciated. Thanks

    My suggestion is to make an appointment at your local Apple Store to have them look at it and see what is wrong with your MBP.

  • Why won't my messages sync on both my iphone and ipad?

    Since I've installed the latest software update for my iphone 4 and ipad 3 my messages are not syncing with both devices.  Today for example I had a message sent to me at 2pm that went to my ipad (which was at home) instead of my phone.
    Does anyone know how to fix this? I have the same email address and contact number set up for both........

    I found a solution that worked for me. I had this same problem and I feel like I tried everything. No matter how many time I synced, the songs appeared to be on my phone, but they would just get skipped over if I tried to play them ("ghost" songs). The answer is not checking and unchecking artists/playlists/etc in iTunes. The phone still thinks the songs are there so it won't sync them to the phone. Here's what to do: go to Settings --> Music and then make sure "Show All Music" is off. Then go to the Music app and try to play through your songs. Now, when a song is skipped over it should no longer appear in the iPhone's library. Once all songs are skipped (could take a few minutes depending on the size of your library), the "ghost" songs will disappear. On the next sync iTunes will put them all back on the phone. Hope this helps.

  • Why won't group messages on iPhone 5 work

    My iPhone 5 won't let me send messages it lets me receive but it doesn't let me send any messages

    please help

  • Why won't my mobile number verify on my iMessages?

    I had my iMessages working but turned off iMessage as not needed. Now can't get mobile number back or verified on iMessage or FaceTime, tried resetting networks & iPad no luck!!! Help!

    Hi Mamand66,
    Thanks for visiting Apple Support Communities.
    If you're not able to activate iMessage with your phone number, these troubleshooting steps can help:
    iOS: Troubleshooting FaceTime and iMessage activation
    http://support.apple.com/kb/ts4268
    If you see "Waiting for Activation" when trying to activate your phone number with iMessage or FaceTime on iPhone
    To resolve this issue:
    Ensure that you have an active Internet connection. You can complete activation using Wi-Fi or a cellular data connection. If you need help connecting to Wi-Fi, follow these steps.
    Update to the latest version of iOS.
    Ensure that FaceTime hasn't been restricted: tap Settings > General > Restrictions > FaceTime.
    Ensure that your iPhone is set to the correct time zone: tap Settings > General > Date & Time.
    Note: If Set Automatically is on but the incorrect time zone appears, turn Set Automatically off and choose the correct time zone, date, and time.
    Verify that you can send SMS messages. You need a valid SMS messaging plan to activate FaceTime and iMessage.
    Contact your carrier to verify that there are no restrictions or blocks on text messages. Blocks on text messaging will prevent iMessage and FaceTime registration.
    If "Waiting for Activation" still appears after you perform these steps, turn FaceTime and iMessage off and on in Settings > Messages and Settings > FaceTime. You may need to wait up to 24 hours to complete activation. Most attempts will take less than an hour, but some attempts may take up to 24 hours. If your issue isn't resolved after 24 hours, please contact Apple for assistance. If you've recently performed a remote wipe on your iPhone, wait 24 hours from the time you performed the remote wipe, and then turn iMessage off then back on.
    Cheers,
    Jeremy

  • Why won't my messages delete on my iphone?

    I deleted all of my FaceBook messages via my PC.  BUT they will not delete on my iphone; they still appear.  I've tried holding and the only option is the archive and even when I try doing that, they re-apear.

    You would need to ask the facebook developer or look at their support site.

  • Why won't iCloud message go away?

    My ipad has a message on the main screen that says:  This ipad has not been backed up in 4 weeks.  The message will not go away when I push OK & it will not let me shut the ipad down.  It is esentially frozen.  I have gone in to manage my icloud to allow more room for back up.  Still not helping. 

    Reset: Hold the Sleep/Wake and Home buttons and don’t let go until the screen goes dark and the Apple logo appears
    Then go to:
    Settings > iCloud > Storage & Backup > Manage Storage > Select your device > Show all apps and turn off anything you don't need backed up.
    You may be too short on local storage to do a back up.
    Check here: Settings > General > Usage
    Try transfering any photos and videos to your computer.

  • Why won't the messages and facetime app work?

    I refuse to believe that the only fix for this is to do all the behind the scenes stuff to change out certain aspects of apps.  I would think that because messages and facetime come built into 10.8.2.  I believe that it is on apple's shoulders to fix this with an update or maybe just an updated messages and facetime app.

    I had my messages and facetime in a folder inside applications, once I copied and pasted the new apps into the folder and clicked replace, they worked just fine, maybe some of you have done the same thing!

  • Why won't video messages from an iphone 4 play properly on my iPhone 4

    When I receive a video message from a 4s phone the video is very distorted and has no sound. I have an iPhone 4. I receive all other videos okay.

    When I was searching for people that had the same problem as me, I found one that said to go on amazon and by a new charger flex. I got the new charger flex and my iPhone charges again. It is not that expensive and my iPhone charges now

  • Why Won't Mail Retain Signatures Copied From One Account to Another?

    I maintain two accounts in Apple Mail: 1) my Exchange account for work, and 2) my .Me account for personal email. My Exchange account has five signatures. Thrice now, I've attempted to add four of the signatures from my Exchange account to my .Me account. Apple Mail seems to make the addition, however, after shutting down Apple Mail and relaunching it, my .Me account is back to 0 signatures. Has anyone else noticed Apple Mail refusing to retain signatures in accounts?

    Let me clarify what you have done, and whether that matches the way Signatures work. There is only one data base of Signatures, and they are composed in Mail Preferences/Signatures. After a Signature has been composed and added to the data base of Signatures, then it must become associated with an account for it to be related to that account. The same Signature can become associated with more than one account, and the method of association is to drag a Signature onto an account name in the Sidebar to the Signatures window.
    At the top of the Sidebar is All Signatures, if you then click on each account below that, then it will be reported which Signatures have been associated with that one account.
    Is this what you have done?
    Ernie

  • Why won't My messages scroll?

    My messages will not scroll

    Try restarting your iPad by holding down the on/off and the home buttons at the same time until you see the Apple logo. 

Maybe you are looking for

  • Certificate Authority is not being seen by windows server 2003 machines

    Good Afternoon, We recently installed a certificate authority using windows server 2008 r2. There was an old certificate authority that had went bad and the role could not be uninstalled on the bad server. The new certificate authority works with win

  • Display two fields in one single cell in a BEx report.

    In a BEx 7 query, we need to display 'First name' and 'Last name' in one cell/column called "Name". The 'First name' and 'Last name' are two different info objects in the multiprovider on which the query is built. These are navigational attributes fo

  • Catching System Error Message in Abap Proxy.

    Hi all,     I want to know whether it is possible to catch the system error message from SXMB_MONI in proxy scenario's.     The error i am getting is : <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> - <!--  Call Adapter   --> - <SAP:Error x

  • Questions about Synchronization

    Hello. I have two questions I need to understand. 1) Is possible to synchronize two iPhones in the same computer using iTunes? 2) I'm using a computer to synchronize my iPhone and I need to change the computer, how can I do it? Is there an easy way t

  • TOP 5 WEBSITES FOR PLUGIN RESEARCH

    ok final question for the day people: If you have to choose 1-5 websites to search for new plugins for purchase what would they be? A website that strickly dedicates it's self to new upcoming plugins and exsistanting plugins and there performance.