Mercurial > mercurial > hgweb_rsearcher.cgi
comparison go/crypto.go @ 0:d3b8cd5aeb70
make repo.
| author | pyon@macmini |
|---|---|
| date | Sun, 30 Sep 2018 17:27:04 +0900 |
| parents | |
| children | db4813125eb8 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:d3b8cd5aeb70 |
|---|---|
| 1 /* | |
| 2 crypto.go : crypto-program. | |
| 3 Version : 0.0 | |
| 4 Last Change: 2018-09-30 Sun 16:47:45. | |
| 5 | |
| 6 install to: rsearcher_root/ | |
| 7 server_root/ | |
| 8 */ | |
| 9 package main | |
| 10 | |
| 11 import ( | |
| 12 "crypto/sha256" | |
| 13 "fmt" | |
| 14 "flag" | |
| 15 "os" | |
| 16 ) | |
| 17 | |
| 18 func main() { | |
| 19 salt := flag.String( "s", "#!@-", "salt." ) | |
| 20 enca := flag.String( "a", "", "encrypt plaintext." ) | |
| 21 encb := flag.String( "b", "", "encrypt csv-file." ) | |
| 22 coll := flag.String( "c", "", "collate user/password." ) | |
| 23 | |
| 24 decr := flag.String( "d", "", "deecrypt hhs." ) | |
| 25 encr := flag.String( "e", "", "encrypt hhs." ) | |
| 26 chdb := flag.String( "f", "", "collate hhs." ) | |
| 27 chhs := flag.String( "g", "", "collate hhs." ) | |
| 28 | |
| 29 flag.Parse() | |
| 30 | |
| 31 if *enca != "" { | |
| 32 buf := *salt + enc_sha256( *enca ) + *salt | |
| 33 fmt.Println( enc_sha256( buf ) ) | |
| 34 os.Exit( 0 ) // done. | |
| 35 } | |
| 36 | |
| 37 if *encb != "" { | |
| 38 r := csv.NewReader(strings.NewReader(in)) | |
| 39 for { | |
| 40 record, err := r.Read() | |
| 41 if err == io.EOF { | |
| 42 break | |
| 43 } | |
| 44 if err != nil { | |
| 45 log.Fatal( err ) | |
| 46 } | |
| 47 buf := *salt + enc_sha256( record[1] ) + *salt | |
| 48 fmt.Println( record[0], ",", enc_sha256( buf ) ) | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 if *coll != "" { | |
| 53 } | |
| 54 | |
| 55 if *decr != "" { | |
| 56 } | |
| 57 | |
| 58 if *encr != "" { | |
| 59 } | |
| 60 | |
| 61 if *chdb != "" && *chhs != "" { | |
| 62 } | |
| 63 | |
| 64 fmt.Fprintf( os.Stderr, "bad argument\n" ) | |
| 65 os.Exit( 1 ) | |
| 66 } | |
| 67 | |
| 68 func enc_sha256( text string ) string { | |
| 69 h := sha256.New() | |
| 70 h.Write( []byte( text ) ) | |
| 71 return fmt.Sprintf( "%x", h.Sum( nil ) ) | |
| 72 } | |
| 73 | |
| 74 func encrypt( text string ) []byte { | |
| 75 return nil | |
| 76 } | |
| 77 |
