-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathencrypto.go
54 lines (47 loc) · 1.01 KB
/
encrypto.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* @Author: xeodou
* @Date: 2015
* @Last Modified by: xeodou
*/
package main
import (
"database/sql"
"fmt"
_ "github.com/xeodou/go-sqlcipher"
)
func main() {
db, err := sql.Open("sqlite3", "users.db?_key=123456")
if err != nil {
fmt.Println(err)
}
defer db.Close()
p := "PRAGMA key = '123456';"
_, err = db.Exec(p)
if err != nil {
fmt.Println(err)
}
c := "CREATE TABLE IF NOT EXISTS `users` (`id` INTEGER PRIMARY KEY, `name` char, `password` chart, UNIQUE(`name`));"
_, err = db.Exec(c)
if err != nil {
fmt.Println(err)
return
}
d := "INSERT INTO `users` (name, password) values('xeodou', 123456);"
_, err = db.Exec(d)
if err != nil {
fmt.Println(err)
}
e := "select name, password from users where name='xeodou';"
rows, err := db.Query(e)
if err != nil {
fmt.Println(err)
}
defer rows.Close()
for rows.Next() {
var name string
var password string
rows.Scan(&name, &password)
fmt.Print("{\"name\":\"" + name + "\", \"password\": \"" + password + "\"}")
}
rows.Close()
}