How can I hash with the MD5 for file

I am a new learner in Java.
Is there any useful code example or materials for me to learn how can i hash with MD5 for file.

import java.security.*;
import sun.security.provider.Sun;
import java.io.*;
import sun.misc.*;
public class DigestOfFile
    public DigestOfFile(String mode) throws Exception
        assert(mode != null);
        digestAgent = MessageDigest.getInstance(mode, "SUN");
    synchronized public byte[] digestAsByteArray(File file) throws Exception
        assert(file != null);
        digestAgent.reset();
        InputStream is = new BufferedInputStream(new FileInputStream(file));
        for (int bytesRead = 0; (bytesRead = is.read(buffer)) >= 0;)
            digestAgent.update(buffer, 0, bytesRead);
        is.close();
        byte[] digest = digestAgent.digest();
        return digest;
    synchronized public String digestAsBase64(File file) throws Exception
        byte[] digest = digestAsByteArray(file);
        String digestAsBase64 = base64Encoder.encode(digest);
        return digestAsBase64;
    synchronized public String digestAsHex(File file) throws Exception
        byte[] digest = digestAsByteArray(file);
        String digestAsHex = encodeBytesAsHex(digest);
        return digestAsHex;
    private static String encodeBytesAsHex(byte[] bites)
        char[] hexChars = new char[bites.length*2];
        for (int charIndex = 0, startIndex = 0; charIndex < hexChars.length;)
            int bite = bites[startIndex++] & 0xff;
            hexChars[charIndex++] = HEX_CHARS[bite >> 4];
            hexChars[charIndex++] = HEX_CHARS[bite & 0xf];
        return new String(hexChars);
    private static final char[] HEX_CHARS =
    {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
    private MessageDigest digestAgent;
    private BASE64Encoder base64Encoder = new BASE64Encoder();
    private byte[] buffer = new byte[4096];
    public static void main(String[] args)
        try
            java.security.Security.addProvider(new Sun());
            DigestOfFile shaDigestAgent = new DigestOfFile("SHA");
            DigestOfFile md5DigestAgent = new DigestOfFile("MD5");
            for (int argIndex = 0; argIndex < args.length; argIndex++)
                    String base64Digest = shaDigestAgent.digestAsBase64(new File(args[argIndex]));
                    System.out.println("Base64 SHA of " + args[argIndex] + " = [" + base64Digest + "]");
                    String hexDigest = shaDigestAgent.digestAsHex(new File(args[argIndex]));
                    System.out.println("Hex    SHA of " + args[argIndex] + " = [" + hexDigest + "]");
                    String base64Digest = md5DigestAgent.digestAsBase64(new File(args[argIndex]));
                    System.out.println("Base64 MD5 of " + args[argIndex] + " = [" + base64Digest + "]");
                    String hexDigest = md5DigestAgent.digestAsHex(new File(args[argIndex]));
                    System.out.println("Hex    MD5 of " + args[argIndex] + " = [" + hexDigest + "]");
        catch (Exception e)
            e.printStackTrace(System.out);
}

Similar Messages

  • I downloaded 11.1 but now can't access the store, can only view my library. I've reinstalled but still get a blank, white screen when I try to go to the itunes store. How can I get to the store for purchases?

    I downloaded 11.1 but now can't access the store, can only view my library. I've reinstalled but still get a blank, white screen when I try to go to the itunes store. How can I get to the store for purchases?

    In iTunes prefs>Store - is the Store check box unchecked?
    Did you repair pemissions with Disk Utility?
    MJ

  • As good will gesture, we can help you with the upgrade for PSE 13. We would request you to place the order for Adobe Photoshop Elements 13 as an upgrade and then we will provide you the full version serial number for the same product against the new upgra

    I RECIVED AN EMAIL FROM ADOBE AS  :  As good will gesture, we can help you with the upgrade for PSE 13. We would request you to place the order for Adobe Photoshop Elements 13 as an upgrade and then we will provide you the full version serial number for the same product against the new upgrade order"  IS THIS UPGRADE FREE AND WHAT SHOULD I DO, HOW CAN I HAVE THIS UPGRADE?

    Compare with on-line stores. The full version is often cheaper than Adobe's upgrade price.
    See this example from Amazon, but check pricing in your own region.
    http://www.amazon.com/gp/product/B00N4OLCRO/ref=s9_simh_gw_p65_d4_i2?pf_rd_m=ATVPDKIKX0DER &pf_rd_s=desktop-1&pf_rd_r=0F1GED9546928YP3PHC0&pf_rd_t=36701&pf_rd_p=1970559082&pf_rd_i=d esktop

  • How can I print with the black and white cartridge only?

    I am trying to print using the black and white cartridge only because magenta is out of ink but I'm getting the following error message in HP Photosmart C7200 series print dialog:
    The printer is out of ink.
    The following ink cartridges are empty: Magenta. Replace these ink cartridges to resume printing.
    How can I print with the black and white cartridge only?
    Mac OSX 10.7.3
    HP Photosmart C7280 (7200 series)
    This question was solved.
    View Solution.

    I am absolutely disgusted by this; clearly a scam from HP to make more money by selling extra ink cartridges!!  I will make sure to never buy any products from the shoddy rip off merchants at HP ever again!!
    You should be ashamed!!

  • Slave instance can not synchronized with the master for a long time

    Hi,
    Slave instance can not synchronized with the master for a long time, and the gap of LSNs between slave and master are more and more larger. The transfer bytes per second between master and slave is 118MB/s , upper limit to the ethernet card. Why???
    ENVIRONMENT:
    1. A network program which we called mcdb is based on BDB 4.8.30. It is used to accept get/set requests and then query data from bdb or save data to bdb.
    2. mcdb implements replication with bdb replication manager api. The default start replication policy is DB_REP_ELECTION, rep ack policy is DB_REPMGR_ACKS_ONE_PEER and rep priority is 100.
    3. The bdb data files, bdb log files, region files and rep files are all in the same home directory.
    4. There are two instances of the mcdb are separately on two standalone servers which has no other programs. These two instances are in one replication group which can elect a master automatically.
    5. The master instance is online, which has lots of requests (get, set, delete).
    ACTIONS:
    1. Start two mcdb instances on two servers and the two instance make a replication group. Slave has already synchronized with the master.
    2. Stop the slave for a long time (more than 20 hours).
    3. Start the slave instance to synchronize data with master.
    RESULT:
    1. the gap of LSNs between slave and master are more and more larger.
    2. db_stat of master and slave:
    master db_stat:
    467170     Number of PERM messages not acknowledged
    9245     Number of messages queued due to network delay
    172415     Number of messages discarded due to queue length
    25880     Number of existing connections dropped
    3407     Number of failed new connection attempts
    =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    DB_REPMGR site information:
    10.67.15.146 (eid: 0, port: 30011)
    Environment configured as a replication master
    331726/3574994     Next LSN to be used
    0/0     Not waiting for any missed log records
    328872/466092     Maximum permanent LSN
    0     Next page number expected
    0     Not waiting for any missed pages
    0     Number of duplicate master conditions originally detected at this site
    2147M     Current environment ID (2147483647)
    100     Current environment priority
    49     Current generation number
    50     Election generation number for the current or next election
    2323     Number of duplicate log records received
    0     Number of log records currently queued
    6768     Maximum number of log records ever queued at once
    55284     Total number of log records queued
    120M     Number of log records received and appended to the log (120475988)
    111     Number of log records missed and requested
    2147M     Current master ID (2147483647)
    2     Number of times the master has changed
    0     Number of messages received with a bad generation number
    8505306     Number of messages received and processed
    12     Number of messages ignored due to pending recovery
    471869     Number of failed message sends
    12M     Number of messages sent (12959945)
    0     Number of new site messages received
    1     Number of environments believed to be in the replication group
    990543     Transmission limited
    0     Number of outdated conditions detected
    0     Number of duplicate page records received
    0     Number of page records received and added to databases
    0     Number of page records missed and requested
    Startup complete
    6244678     Number of transactions applied
    0     Number of startsync messages delayed
    1     Number of elections held
    1     Number of elections won
    No election in progress
    0.057097     Duration of last election (seconds)
    8944103     Number of bulk buffer sends triggered by full buffer
    0     Number of single records exceeding bulk buffer size
    5273M     Number of records added to a bulk buffer (5273592170)
    10M     Number of bulk buffers sent (10490865)
    0     Number of re-request messages received
    0     Number of request messages this client failed to process
    0     Number of request messages received by this client
    slave db_stat:
    0     Number of PERM messages not acknowledged
    0     Number of messages queued due to network delay
    0     Number of messages discarded due to queue length
    1454     Number of existing connections dropped
    0     Number of failed new connection attempts
    =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    DB_REPMGR site information:
    10.67.15.147 (eid: 0, port: 30011)
    Environment configured as a replication client
    329544/2916048     Next LSN expected
    330433/2013808     LSN of first log record we have after missed log records
    329543/5500501     Maximum permanent LSN
    0     Next page number expected
    0     Not waiting for any missed pages
    0     Number of duplicate master conditions originally detected at this site
    2147M     Current environment ID (2147483647)
    100     Current environment priority
    49     Current generation number
    50     Election generation number for the current or next election
    5256M     Number of duplicate log records received (5256599432)
    3925284     Number of log records currently queued
    3925285     Maximum number of log records ever queued at once
    4880561     Total number of log records queued
    3578038     Number of log records received and appended to the log
    1912297     Number of log records missed and requested
    0     Current master ID
    1     Number of times the master has changed
    0     Number of messages received with a bad generation number
    12M     Number of messages received and processed (12980442)
    2     Number of messages ignored due to pending recovery
    0     Number of failed message sends
    1912307     Number of messages sent
    0     Number of new site messages received
    0     Number of environments believed to be in the replication group
    0     Transmission limited
    0     Number of outdated conditions detected
    0     Number of duplicate page records received
    0     Number of page records received and added to databases
    0     Number of page records missed and requested
    Startup incomplete
    110568     Number of transactions applied
    80     Number of startsync messages delayed
    0     Number of elections held
    0     Number of elections won
    No election in progress
    0     Number of bulk buffer sends triggered by full buffer
    0     Number of single records exceeding bulk buffer size
    0     Number of records added to a bulk buffer
    0     Number of bulk buffers sent
    0     Number of re-request messages received
    0     Number of request messages this client failed to process
    0     Number of request messages received by this client
    Edited by: 899585 on 2013-1-4 下午10:54
    Edited by: 899585 on 2013-1-4 下午10:55

    Hi,
    Unfortunately, this issue is beyond the level of what is supported over the forum. Performance related issues are extremely complex and require an in-depth understanding of your environment and dedicated support. In a generic sense, you can look at this as a basic queueing problem. You have a server that went down and work is still coming in. When the server gets started it is possible that it may never catch up depending on new work coming in and the rate at processing the old work.
    So what would you do in this case --- one thing would be to reduce the new work coming in. In HA terms this would be slowing the master down and you can increase DB_REP_ACK_TIMEOUT for this. Another thing you could do is add fresh servers to help reduce the workload. In HA terms, this would be the equivalent of restarting the client and give it a fresh look at everything. Another thing you could do is replan the system and load balance. In HA terms, it would mean something like take a hot backup of the master and reinit a client from scratch.
    If you are interested in getting a dedicated support person working on this concern, please let me know and we can move forward down that path. Just respond to the thread with your email address and I will get in contact with you so we can pursue that approach.
    thanks
    mike

  • HT2404 How can I speed up the updates for my apps on my iphone 4 ?

    How can I speed up the updates for my apps on my iphone 4?  They take forever and/or a window says that the update will be available when I connect my iphone to itunes on my computer which doesn't help.

    I don't have virus protection on my iphone so this answer in not applicable

  • HT201365 I like the additional security features but don 't want to type in a password every time I use my phone.  How can I turn off the requirement for a password but leave "Find my Phone" active?

    I like the additional security features but don 't want to type in a password every time I use my phone.  How can I turn off the requirement for a password but leave "Find my Phone" active?

    Settings>General>Passcode Lock...enter your passcode, then: Turn Passcode Off.

  • How can I connect with the AspNetUsers table in MVC 5?

    I have a model, in which I have used several foreign keys from other tables. The point is that I also need to get the Id of the user, from the AspNetUsers table, though, I don't know how. I have done something like this, but it doesn't seem to be working:
    public class Message
        public int MessageID { get; set; }
        [Required(ErrorMessage="Please type a message to submit")]
        [DataType(DataType.MultilineText)]
        [Display(Name="Message")]
        public string MessageText { get; set; }
        public DateTime WrittenOn { get; set; }
        [Required(ErrorMessage="Please select a ticket")]
        [ForeignKey("Ticket")]
        [Display(Name="Ticket")]
        public int TicketID { get; set; }
        public virtual Ticket Ticket { get; set; }
        [Required(ErrorMessage = "Please select a business")]
        [ForeignKey("Business")]
        [Display(Name = "Business")]
        public int BusinessID { get; set; }
        public virtual Business Business { get; set; }
        [Required(ErrorMessage = "Please select a user")]
        [ForeignKey("aspnetusers")]
        [Display(Name = "User")]
        public int Id { get; set; }
        public virtual ApplicationUser ApplicationUser { get; set; }
    When I try to create a controller using the Entity Framework with my model, I get an error message saying:
        The ForeignKeyAttribute on property 'Id' on type ... is not valid. The navigation property 'aspnetusers' was not found on the dependent type ... The Name value should be a valid navigation property name.
    If someone could help me solve the problem, I would be glad.

    Hi Toni,
    I see that this particular query is been answered in the following thread.
    http://stackoverflow.com/questions/25372436/how-can-i-connect-with-the-aspnetusers-table-in-mvc-5
    You can also refer the following links, hope this helps.
    http://stackoverflow.com/questions/20071282/aspnet-identity-and-mvc5
    http://blogs.msdn.com/b/webdev/archive/2013/10/16/customizing-profile-information-in-asp-net-identity-in-vs-2013-templates.aspx
    Regards,
    Bharath

  • How can you turn off the sounds for receiving a text or e-mail while on a phone call???

    How can you turn off the sounds for receiving a text or e-mail while on a phone call???

    That's the most stupid thing. It may work but the phone shouldn't be going off in your ear while in use from the start.
    Message was edited by: Ford Truck

  • How can I turn off the ringtone for a contact?

    How can I turn off the ringtone for a contact on my iphone 5c?

    krwspike wrote:
    I purchased IPhone silent ringtone
    I've found silent ringtones well worth the investment.

  • HT201274 Can a Sprint Iphone 5 work with T-mobile network? How can one unlock with the MSL code? Sprint is not abiding by the Unlocking Consumer Choice and Wireless Competition Act.  FCC will only enforce if we file more complains.

    Can a Sprint Iphone 5 work with T-mobile network? How can one unlock with the MSL code? Sprint is not abiding by the Unlocking Consumer Choice and Wireless Competition Act.  FCC will only enforce if we file more complains.

    T-Mobile is a GSM network whereas Sprint is a CDMA network. They are incompatible. Sprint is not obliged to unlock a phone that is still under contract. Their phones may not be capable of being unlocked.

  • HT5177 How can two people edit the same FCPX file? One company, so both people/computers share the same license. Example: I work on revision A and my boss takes it and makes revision B and gives it back to me using two separate computers.

    How can two people edit the same FCPX file? One company, so both people/computers share the same license. Example: I work on revision A and my boss takes it and makes revision B and gives it back to me using two separate computers.

    Have the project, events and media on one drive which is common to both macs.
    You can download FCP X to both macs using the same Apple ID that it was purchased with.
    Andy

  • I have Firefox 10.0.2. and OSX 10.6.8. and the latest PDF adobe reader, and still can not open with the browser PDF files.Can someone help,pls?Thanx

    Dear Ones,
    I have Firefox 10.0.2. and OSX 10.6.8. and the latest PDF adobe reader, and still can not open with the browser PDF files.Can someone help,pls?Thanx

    see if this is helpful : [http://support.mozilla.org/en-US/kb/Opening%20PDF%20files%20within%20Firefox Opening PDF files within Firefox]
    thank you
    Please mark "Solved" the answer that really solve the problem, to help others with a similar problem.

  • I failed to register on photoshop in time. How can I work with the  photos I have there?

    I already have photos on my computer in Photoshop but I failed to register within the time limit, so now I cannot do anythiing with my photos. How can I get to use my photos that I already have on photoshop? I am just now  signing up for an account on Photoshop.

    Bryant,
    Your photos aren't stored in Photoshop. They are stored on the hard drive, they only open in Photoshop.
    Check your hard disk for the photos you're searching for.
    -ST

  • I am getting  blank screen with the symbol for files and a question mark on top of it on my imac. How do i resolve this?

    When I start up my iMac, I get this blank screen with a flashing ? (question mar). how do I resolve this?

    abhayakumar wrote:
    Here's what I did. I pressed options moment I powered on the iMAC and it started up.
    The blinking folder + ? means that the Mac can't find your startup disk. Holding option down after the chime means you're forcing the Mac to look for any version of OS X on any connected disk. If it then finds your HD and starts up, one of the following needs to be done :
    1. Verify and if necessary Repair your HD using Disk Utility
    2. Repair Permissions using Disk Utility
    3. If there is a slowly developing issue with the HD it may need to be replaced
    4. If none of the above, it could be the logic board (usually capacitors)

Maybe you are looking for