Block Chain Foundation: Wallet Design __ Block chain

Source: Internet
Author: User
Tags md5
1, wallet design
Package Com.blockchain.model;
Import Java.util.Map;
Import Com.blockchain.security.CryptoUtil;

Import Com.blockchain.security.RSACoder;
    /** * Wallet: Public key, private key, wallet address * * Public class Wallet {/** * key/private String PublicKey;
    /** * Private Key * */private String Privatekey;

    /** * Wallet Address */private String address=null; 
     /** * Hidden parameterless constructor/private Wallet () {}/** * contains only the public key wallet, used for other nodes, other nodes need to use * @param when transferring PublicKey
        * * Public Wallet (String publickey) {this.publickey = PublicKey;
    This.address= cryptoutil.md5 (Hashpubkey (PublicKey)); /** * This constructor is only for static method Createwallet () using * @param publickey * @param privatekey * * Private Wallet (St
        Ring PublicKey, String privatekey) {this.publickey = PublicKey;
        This.privatekey = Privatekey;
    This.address= cryptoutil.md5 (Hashpubkey (PublicKey)); /** * Generate a new wallet, which is to generate a new key pair * @return/PubLic static Wallet Createwallet () {map<string, object> initkey;
            try {//local generate public private key to Initkey = Rsacoder.initkey ();
            String PublicKey = Rsacoder.getpublickey (Initkey);
            String Privatekey = Rsacoder.getprivatekey (Initkey);
        return new Wallet (PublicKey, Privatekey);
        catch (Exception e) {e.printstacktrace ();
    return null;
    public void setaddress (String address) {this.address = address;
        /** * Get wallet Address: Generate wallet address by public key * @return * * * getaddress ().
            if (null==address) {String Publickeyhash = Hashpubkey (PublicKey);
        Return Cryptoutil.md5 (Publickeyhash);
        }else{return address; }/** * Static method: Generates wallet Address * @param publickey * @return/public static String according to the specified wallet key getaddr ESS (String publickey) {string Publickeyhash= Hashpubkey (PublicKey);
    Return Cryptoutil.md5 (Publickeyhash);
    Public String Getpublickey () {return publickey;
    } public void Setpublickey (String publickey) {this.publickey = PublicKey;
    Public String Getprivatekey () {return privatekey;
    } public void Setprivatekey (String privatekey) {this.privatekey = Privatekey; /** * Get wallet public key Hash * * @return * * * Gethashpubkey () {return cryptoutil.
    SHA256 (PublicKey); /** * Generate wallet Public key hash * * @param publickey * @return * * (* * * () (* * * * hashpubkey) (St
    Ring PublicKey) {return cryptoutil.sha256 (PublicKey);
 }

}
2. Test Code
Package Com.blockchian.model;

Import Org.junit.Before;
Import Org.junit.Test;
Import Com.blockchain.model.Wallet;

public class Wallettest {
    @Before public
    void SetUp () throws Exception {
    }

    @Test public
    Void Testwallet () throws Exception {
        Wallet wallet=wallet.createwallet ();
        SYSTEM.OUT.PRINTLN ("Wallet address: \ n" +wallet.getaddress ());
        SYSTEM.OUT.PRINTLN ("wallet public key: \ n" +wallet.getpublickey ());
        SYSTEM.OUT.PRINTLN ("Wallet private key: \ n" +wallet.getprivatekey ());
    }

Test results

Wallet Address: A2E2B8849C1D874D14884E914A8A0C20 Wallet Public key:
Migfma0gcsqgsib3dqebaquaa4gnadcbiqkbgqca0ojspupzte4rzvzcyjynljyr5xhvkwxdawey Byszqaejdlvddgcas0lcfvacbvswfhikm8xbml0umvtcaof6ghtoaqrnziouazjp3quu25id13er wOgoxT7DTNF99GZaFo2dgOS+ Iyfwqlyz6yw9qkbaum1a3pygi6zqxfjedwidaqab Wallet private key: miicdwibadanbgkqhkig9w0baqefaascamewggjdageaaogbaidsinklsno0thho/
NXGLICUNHHL cdwtdf0bz5htixmpoqkmtummzxplqsj9uaju+zb8eksbxcewvs6zvmich/qadogcqs3oi64dom/d C67BMIPXD6VA6CJFPSNM0X30ZLOWJZ2A5L4HGXCQXJNRJB1APSBSBVRC/IYJPMREWN53AGMBAAEC gYBB1dbQ+ gjduxdyijuxt1dlgytk6alokjf38qdt+j/pjk7e5ja4pl0gxhg/pbwnglrm47/wob/p hk4ay4g6gnqligx8l4gglxtogtoiuhc8tm+jaff2/ PUXZL7AGGBJGGS2Z7WIUJCKOTXXJ86YOUC9 ur7p8dh4b7hu/ramqms96qjbanta9sv/ps/ Seubfdy6uysbwuxvh3ff7dooiumeuycmy9lm4xfas mxbr+okoa/ Fepwvmvh55wwfp1stigzbrnlscqqca7x34vgjf5e3te14nhl1mwru1okrb8rr7f3my fkipzqli+2xhwllbje2ydn+3yyfl1scrgdum4xk/ QJBGG391AKEA0YKPJFY+QBJ7BLBXJHUAP1SQ rmmnvd+ukqltasc/kvwwb3p06qfnkiiwxili8dqdzgbf4yticrmgj58xhpaqxwjann/ Yhhrqjwkz NV9DTKNSBYHFYQCPLUOBIIIE0FYUGKH6YNJDRUEQQRKJMYSZXCEZBC7YFTYSFWXDWT3P6AA4MQJB ak+av4qfuhkgu/cojpmkgpsn8opex9uknxxnhv0pusq+ SEC971P0CAV4ZLW3NF07OPAJANGY7FGE ivbgq2iblbq=

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.