开发者

java android URL encrypting

I am working on an application that uploads a file to amazon s3(part of the application). But when I gene开发者_JAVA技巧rate the URL of the files, it shows the authentication key, file name and etc. I need to encrypt the URL. Also I am using tiny url to shorten the URL but when I put the curser on the link it shows the real URL. I looked for md5 but I couldn't make it work. Is there any suggestion?


I will try to explain how MD5 works

import java.math.*;
import java.security.*;

public class testMain {

    /**
     * @param args
     */
    public static void main(String[] args) {

        String stringThatNeedsToBeEncrpyted = "yourURL"; // Value to encrypt
        MessageDigest mdEnc = null;
        try {
            mdEnc = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } // Encryption algorithm
        mdEnc.update(stringThatNeedsToBeEncrpyted.getBytes(), 0, stringThatNeedsToBeEncrpyted.length());
        String md5 = new BigInteger(1, mdEnc.digest()).toString(16); //Make the Encrypted string
        System.out.println(md5); //print the string in the console

    }   
}

The output is : 7f5976785d03c60f9fd4b08fb78e72ce

This is your message digest.

EDIT

Hashing a username and password should always be done with an appropriate hashing algorithm like PBKDF2, bcrypt or scrypt. Furthermore always use SSL to transfer confidential data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜