How to use (un) padded hash to verify signature

Hi,
Thanks to the person that posted the code for padding a Hash in the topic http://forum.java.sun.com/thread.jspa?forumID=9&threadID=657241
It helped a lot !
Now, I want to do the reverse. I want to verify that the signature created matches the calculated hash in the file.
This is my code to create the signature file assuming that I have the hash of the file to be signed:
  public void signHash( byte[] bHash, String szSignHashFile )
         Cipher rsaCipher = Cipher.getInstance("RSA/ECB/NoPadding","BC");
          rsaCipher.init(Cipher.ENCRYPT_MODE, privKey);   
         byte[] bPaddedHash =  padHash (bHash, (RSAPrivateKey) privKey);
         byte[] enc = rsaCipher.doFinal(bPaddedHash);
         ByteBuffer bbuf = ByteBuffer.allocate(enc.length).put(enc);
         bbuf.flip();
         File fOutput = new File(szSignHashFile);
         // FileReader frInput = new FileReader(fInput);
         // FileWriter fwOutput = new FileWriter(fOutput);
         FileChannel wChannel = new FileOutputStream(fOutput, false).getChannel();
         wChannel.write( bbuf );
         wChannel.close();now, I need a verifyHash ( byte[] bHash, String szSignHashFile ) function that reads the file with the signature, decrypts the signature with the RSAPublicKey and compares the result with the passed hash to verify if the file has been tampered with. The problem is that I don't know how to unpad the byte array created when I call rsaCipher.doFinal(bSignatureByteArray) in DECRYPT MODE to give me the 20bytes of the original hash so I can compare them. Can somebody help with the unpadding hash function?
Thanks,
Juan C.

Thank you for this post and for the other posts. They have been very helpful.

Similar Messages

  • Hi, how to use touch pad (thinkPad T61) to scroll pages up/down, left/right? do I need any drivers?

    Hi, how to use touch pad (thinkPad T61) to scroll pages up/down, left/right? do I need any drivers?

    Hi daneeo, and welcome to the Lenovo User Community!
    In the Control Panel for your Mouse there should be an UltraNav tab. Under that tab are all the settings for the touchpad. Check to make sure scrolling is enabled.
    If you do not see an UltraNav tab in the Mouse Control Panel, download and install the UltraNav driver and utility:
    http://www-307.ibm.com/pc/support/site.wss/document.do?lndocid=MIGR-66898
    http://www-307.ibm.com/pc/support/site.wss/document.do?lndocid=MIGR-67226
    Hope this helps!
    I don't work for Lenovo. I'm a crazy volunteer!

  • HT3981 how can use track pad in windows using macbook

    Hi everyone.
    Can anyone guide me , How can we use track Pad click and right click in Macbook while running Windows 7.?
    Kind regards,
    Kabir

    It appears you did not complete the installation and set up of Windows. Did you install the Boot Camp support software/drivers from your Snow Leopard installation disk? If you did you shouls have the Boot Camp Tools icon on your Windows. Access these tools and set up the track pad.

  • How to use self-signed certificate to verify others certificate?

    the self-signed certificate and keys acts as CA like VeriSign
    alias =SelfSignCA
    keystore = SelfSignLib
    certificate = SelfSign.cer
    certificate to be verify
    alias = companyCA
    certificate = companyLib
    csr file = company.csr
    how to use keytool to verify/sign the company certificate?thank you.

    Well, this might not be much help, but for 10g, on AIX, docID 1171558.1 describes how to create a new certificate.
    Not sure how relevant it will be for 11g, sorry :(

  • How to use i pad 2 as second monitor

    does anyone know how i can use my i pad 2 as a second monitor to my mac book pro?

    You can try Air Display.
    https://itunes.apple.com/sg/app/air-display/id368158927?mt=8&ls=1

  • Do you have classes to learn how to use I pad

    Do you have classes in Reno nv to use the I pad

    You are not talking to Apple here - just other users who are here to help each other sort through problems with the iPad. All Apple Stores have Genius Bars where you can book an appointment with an Apple Genius if you want one on one instruction with the iPad.
    Apple Retail Store - Summit Sierra
    There are many tutorials that you can watch online starting with Apple's iPad guided tours.
    Apple-iPad 2-Guided Tours
    You can Google for even more tutorials or just click on this.
    This is what Google came up with when I entered iPad online tutorials in the search field

  • How to use Oracle temporary table and verify if it exists

    1. I got two errors on the following code.
    ORA-06550: line 13, column 4:
    PLS-00428: an INTO clause is expected in this SELECT statement
    ORA-06550: line 17, column 3:
    PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:
    2. Can I include this code in the create view statement?
    Thanks ahead, I am new to oracle dev world.
    ===========================================================
    DECLARE
    l_count NUMBER;
    BEGIN
    select count(*)
    into l_count
    from all_tables
    where table_name like 'TEMP_SHOW_STAFF_2%';
    if l_count > 0 then
    select * from TEMP_SHOW_STAFF_2;
    else
    create global temporary table TEMP_SHOW_STAFF_2
    (employee_id Number,
    last_name varchar(10),
    first_name varchar(10),
    salary_amount varchar(10))
    on COMMIT delete rows;
    end if;
    END;

    The PL/SQL User's Guide will have much more information, but as a quick example (new_dept is an empty table with the same structure as the DEPT table in the SCOTT schema).
      1  declare
      2    -- Create the type & declare a variable of that type
      3    type dept_arr_typ is table of dept%rowtype;
      4    dept_arr dept_arr_typ;
      5  begin
      6    -- Populate the type in memory
      7    select *
      8      bulk collect into dept_arr
      9      from dept;
    10    -- Manipulate the data
    11    for i in 1..dept_arr.count
    12    loop
    13      select 'foo'
    14        into dept_arr(i).dname
    15        from dual;
    16    end loop;
    17    -- Write the data back
    18    for i in 1..dept_arr.count
    19    loop
    20      insert into new_dept( deptno, dname, loc )
    21        values( dept_arr(i).deptno, dept_arr(i).dname, dept_arr(i).loc );
    22    end loop;
    23* end;
    SCOTT @ nx102 Local> /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.01
    SCOTT @ nx102 Local> select * from new_dept;
        DEPTNO DNAME          LOC
            10 foo            NEW YORK
            20 foo            DALLAS
            30 foo            CHICAGO
            40 foo            BOSTONOf course, for this sort of thing, we could do everything in a single SQL statement
    INSERT INTO new_dept( deptno, dname, loc )
      SELECT deptno, 'foo', loc
        FROM dept;Collections can be handy if you need to apply a bit more conditional logic, though.
    Justin

  • How to use image from a file in signature appearance.

    Hi,
    I am creating a Plugin for acrobat 9, using PubSec using DocSign sample as basis. I have created the appearance using text objects and the logos data that came with the DocSign sample. But I want to use image from a file (like, jpg) in the signature appearance creation. So far the documentation doesnt tell how to achieve this.
    Can you please tell me in a  "How-to" kinda way to achieve this?
    Thanks in advance.

    Thanks for ur prompt reply.
    There are so many samples in the sdk. which one is the "sample for adding images."?

  • How to use javascript to auto fill a signature

    Hello,
    I am new to Adobe Acrobat Pro 9.  I have scanned a paper form/document that originally  had various data lines to be written on using an ink pen.  I saved the scanned PDF as an Acrobat 9 PDF.  I have added various pertinent text fields and checkboxs to PDF form and saved it with appropriate extended setting to allow end-user to type on PDF and save a copy.  At the bottom form there is a name/signature text field for end-user name to be typed and a calendar text date when name/signature text field is entered .
    I need to send this PDF form to various end-users using (Groupwise/Novell) email to have them sign or type their name and date at bottom of form.  Is there a way that Adobe Acrobat 9/PDF will recognize the email sender and allow the name/signature field to automatically fill-in signature/name textbox.  Are there tools like javascript, etc. that will help me accomplish this task?
    I don't know where to begin. I am a newbie.  Please help!

    Hi Kanza17,
    It's a bit of a lengthy discussion. I'd recommend two places to read up on what seed values are and how to set them. First, check out the Security Admin Guide, specifically Chapter 9 - Controlling Signing with Seed Values. That will give you a good understanding of what a seed value is and what it can do. The next thing to look at is the JavaScript for Acrobat API Reference. Once you get to the web page click the Search button in the left hand panel, type in "Seed Value" (without the quotes) in the edit field, and then click the Go! button. You're looking for the section signatureSetSeedValue and there you will find some examples at the bottom of the page that will help you get started.
    Good luck,
    Steve

  • How to use time from external source as signature time?

    Hi,
    I have a PubSec based acrobat X plugin for signature creation and verification. So far i knew that acrobat was using my local system time to get signing time and saved that time in the signature dictionary. Now i have to get the signing time from an NTP server, which is different from my local system time, and I want to put this time in the signingTime (M) of the Signature dictioniary. But so far i am unable to modify the (M) dictionary value.
    Can you please guide me to achieve this goal?
    thanks

    thanks for your prompt reply.
    actually, using timestamps is not an option. Machine time can be changed and my requirement is to use NTP time during signing and set this time as signing time in the signature dictionary. I have tried adding the time in M dictionary in SigGetSigProperties() and SigGetSigValue() callbacks, but it has no effect.
    My question is, is it possible to use time other, than machine time, as signing time in a signature (in signature dictionary) ?
    If yes, then can i achieve this, a hint or a point in the right direction can suffice.
    if no, then is this limitation part of the new plugin framework? because as far as i remember, it was allowed in digsig plugins.
    Finally, can i achieve my goal in an unorthodox way?
    thanks

  • I do have a gray application DVD that came with my MacBook Pro by how to use it

    I do have a gray application DVD that came with my MacBook Pro by how to use it.

    You don't, your signature says you have 10.7.5 and the disk is either 10.5 or 10.6, has outdated software on it.
    Keep it in case of emergency in a very safe place in case you need to reinstall on a new drive, then upgrade to 10.7.5 again.
    https://discussions.apple.com/community/notebooks/macbook_pro?view=documents

  • How to use electronic signature

    how to use electronic signature

    Hi William,
    An electronic signature is not a cryptographic operation, but rather something akin to typing in your name or attaching a stamp. A digital signature uses a public / private key pair (aka a digital ID) and cryptographically binds the signature to the document so that if the document is altered it will break the signature, thus ensuring document integrity.
    If you are truly looking for a secured method of creating an electronic signature you should do to http://www.echosign.com and subscribe to the service.
    If you want to learn about digital signatures I'd start at http://helpx.adobe.com/acrobat/kb/certificate-signatures.html
    Steve

  • Can not take a screenshot with Maverick and track pad.  can not use apple chat to talk with a tech.  there are other issues also like I used to be able to go back a page with the delete button.  No Maverick PDF to instruct on how to use Maverick

    Can not take a screenshot with Maverick and track pad.  can not use apple chat to talk with a tech.  there are other issues also like I used to be able to go back a page with the delete button.  No Maverick PDF to instruct on how to use Maverick
    THE use of the apple support is a mess also.
    I want to be able to use my MAC fully and easily like I used to with Snow Leopard. 
    What is wrong with this maverick OS?

    The only people who can possibly assist you with this is Apple Customer Relations, call your local Apple contact number and ask for Customer Relations then explain your situation clearly and politely (be firm but don't rant).
    You might want to investiage what the local laws are regarding defective goods and 'fit for use' definitions on warranties etc. Consumer Protection can be a useful tool to use or bargain with if needed ...

  • How to use u sb in i pad, how to use u sb in i pad

    how to use u sb in i pad, how to use u sb in i pad

    You get Apple iPad Camera Connection kit for iPad (1st, 2nd and 3rd Gen) and Lightning to Usb Camera Adapter for (iPad 4th Gen, iPad Mini, iPad Mini with Retina Display and iPad Air) which allows you to connect many Digital Cameras on your iPad and then Import the images directly on your iPad from your Digital Camera.
    http://store.apple.com/us/product/MC531ZM/A/apple-ipad-camera-connection-kit
    http://store.apple.com/us/product/MD821ZM/A/lightning-to-usb-camera-adapter
    Note : You cannot use the connector to connect any other Usb device to your iPad other the Digital Camera as iPad doesn't have supported drivers.

  • How to use 2g networks in pad 2

    how to use 2g networks in pad 2

    Hi,
    ICEfaces isn't yet compatible with Portlets. We're targeting Portlet support in our 1.1 release, slated for this fall.
    Thanks,
    Philip
    ICEsoft Technologies

Maybe you are looking for

  • Browse (Firefox) crashing when Flash Player enabled

    Hello, i'm JoLLDS VOLPE and i'm having trouble with Flash Player Before i format my PC, the flash player (nd the Google Chrome, keep reading for understand this part ) was all fine, not having trouble. I formatted my PC because the very low spce in d

  • HP Officejet Pro 8600 no possibility to configure Port

    My OS is Win 8.1 (last release), last Printer Driver version, last Printer Install Wizard used. My first Printer "HP Officejet Pro 8600" folling down about Screen issue. I do an exchange with same model, i unsinstall and reinstall the full with wizar

  • Can i get a new screen for my ipad2

    hi where is the best place to send my ipad2, its got a cracked screen and didnt want to send it to just any1 for repair, any ideas of cost.

  • Oracle instant client 11g doesn`t connect to database 10g

    hi, i installed a oracle instant client 11g for windows xp on my pc, because i need a odbc connection. I don`nt know this product. I don`t find a tns.ora file, so how can i give them the right parameter for my oracle database and how can i make a odb

  • Rank in a java game

    Hi ppl, I'm newbie in this forum, I'm development a java game and now I would like to implements a rank for players. Basically, I have some players that play to the game and then (at game finish) game will write a .txt file with date, score and name