英文:
Go language: Error during compilation
问题
我正在尝试在Windows 10上编译这个用Go语言编写的程序,但是我遇到了以下错误:
warpwallet_cracker.go:12:2: 找不到包"github.com/vsergeev/btckeygenie/btckey",在以下任何位置都找不到:
C:\Go\src\github.com\vsergeev\btckeygenie\btckey (来自$GOROOT)
C:\Users\user\go\src\github.com\vsergeev\btckeygenie\btckey (来自$GOPATH)
warpwallet_cracker.go:4:5: 找不到包"golang.org/x/crypto/pbkdf2",在以下任何位置都找不到:
C:\Go\src\golang.org\x\crypto\pbkdf2 (来自$GOROOT)
C:\Users\user\go\src\golang.org\x\crypto\pbkdf2 (来自$GOPATH)
warpwallet_cracker.go:5:2: 找不到包"golang.org/x/crypto/scrypt",在以下任何位置都找不到:
C:\Go\src\golang.org\x\crypto\scrypt (来自$GOROOT)
C:\Users\user\go\src\golang.org\x\crypto\scrypt (来自$GOPATH)
Github链接:https://github.com/nachowski/warpwallet_cracker
以下是代码:
package main
import (
"golang.org/x/crypto/pbkdf2"
"golang.org/x/crypto/scrypt"
"bytes"
"crypto/sha256"
"fmt"
"time"
"os"
"math/rand"
"github.com/vsergeev/btckeygenie/btckey"
)
const letterBytes = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
func random(r *rand.Rand, n int) string {
b := make([]byte, n)
for i := range b {
b[i] = letterBytes[r.Intn(62)]
}
return string(b)
}
func main () {
r := rand.New(rand.NewSource(time.Now().Unix()))
var address string
saltValue := ""
if len(os.Args) >= 2 {
address = os.Args[1]
if len(os.Args) == 3 {
saltValue = os.Args[2]
} else {
saltValue = "";
}
} else {
fmt.Printf("Usage: %s [Address] [Salt - optional]\n\n", os.Args[0])
os.Exit(0)
}
fmt.Printf("Using address \"%s\" and salt \"%s\"\n", address, saltValue)
tries := 0
start := time.Now()
for {
passphraseValue := random(r, 8)
result := bruteforce(passphraseValue, saltValue, address);
if result != "" {
fmt.Printf("Found! Passphrase %s\n", passphraseValue)
os.Exit(0)
} else {
tries += 1
fmt.Printf("\rTried %d passphrases in %s [last passphrase: %s]", tries, time.Since(start), passphraseValue)
}
}
}
func bruteforce(passphraseValue string, saltValue string, address string) string {
var priv btckey.PrivateKey
var err error
pass := fmt.Sprint(passphraseValue, "\x01")
salt := fmt.Sprint(saltValue, "\x01")
key, _ := scrypt.Key([]byte(pass), []byte(salt), 262144, 8, 1, 32)
pass = fmt.Sprint(passphraseValue, "\x02")
salt = fmt.Sprint(saltValue, "\x02")
key2 := pbkdf2.Key([]byte(pass), []byte(salt), 65536, 32, sha256.New)
var result bytes.Buffer
for i := 0; i < len(key); i++ {
result.WriteByte(key[i] ^ key2[i])
}
err = priv.FromBytes(result.Bytes())
if err != nil {
fmt.Printf("Error importing private key: %s [%s]\n", err, passphraseValue)
return ""
}
address_uncompressed := priv.ToAddressUncompressed()
if (address_uncompressed == address) {
return passphraseValue
}
return ""
}
我不知道问题可能是什么,有人可以帮助我吗?
英文:
I'm trying to compile this program written in Go on Windows 10 but i get these errors:
warpwallet_cracker.go:12:2: cannot find package "github.com/vsergeev/btckeygenie/btckey" in any of:
C:\Go\src\github.com\vsergeev\btckeygenie\btckey (from $GOROOT)
C:\Users\user\go\src\github.com\vsergeev\btckeygenie\btckey (from $GOPATH)
warpwallet_cracker.go:4:5: cannot find package "golang.org/x/crypto/pbkdf2" in any of:
C:\Go\src\golang.org\x\crypto\pbkdf2 (from $GOROOT)
C:\Users\user\go\src\golang.org\x\crypto\pbkdf2 (from $GOPATH)
warpwallet_cracker.go:5:2: cannot find package "golang.org/x/crypto/scrypt" in any of:
C:\Go\src\golang.org\x\crypto\scrypt (from $GOROOT)
C:\Users\user\go\src\golang.org\x\crypto\scrypt (from $GOPATH)
Github: https://github.com/nachowski/warpwallet_cracker
Here's the code:
package main
import (
"golang.org/x/crypto/pbkdf2"
"golang.org/x/crypto/scrypt"
"bytes"
"crypto/sha256"
"fmt"
"time"
"os"
"math/rand"
"github.com/vsergeev/btckeygenie/btckey"
)
const letterBytes = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
func random(r *rand.Rand, n int) string {
b := make([]byte, n)
for i := range b {
b[i] = letterBytes[r.Intn(62)]
}
return string(b)
}
func main () {
r := rand.New(rand.NewSource(time.Now().Unix()))
var address string
saltValue := ""
if len(os.Args) >= 2 {
address = os.Args[1]
if len(os.Args) == 3 {
saltValue = os.Args[2]
} else {
saltValue = "";
}
} else {
fmt.Printf("Usage: %s [Address] [Salt - optional]\n\n", os.Args[0])
os.Exit(0)
}
fmt.Printf("Using address \"%s\" and salt \"%s\"\n", address, saltValue)
tries := 0
start := time.Now()
for {
passphraseValue := random(r, 8)
result := bruteforce(passphraseValue, saltValue, address);
if result != "" {
fmt.Printf("Found! Passphrase %s\n", passphraseValue)
os.Exit(0)
} else {
tries += 1
fmt.Printf("\rTried %d passphrases in %s [last passphrase: %s]", tries, time.Since(start), passphraseValue)
}
}
}
func bruteforce(passphraseValue string, saltValue string, address string) string {
var priv btckey.PrivateKey
var err error
pass := fmt.Sprint(passphraseValue, "\x01")
salt := fmt.Sprint(saltValue, "\x01")
key, _ := scrypt.Key([]byte(pass), []byte(salt), 262144, 8, 1, 32)
pass = fmt.Sprint(passphraseValue, "\x02")
salt = fmt.Sprint(saltValue, "\x02")
key2 := pbkdf2.Key([]byte(pass), []byte(salt), 65536, 32, sha256.New)
var result bytes.Buffer
for i := 0; i < len(key); i++ {
result.WriteByte(key[i] ^ key2[i])
}
err = priv.FromBytes(result.Bytes())
if err != nil {
fmt.Printf("Error importing private key: %s [%s]\n", err, passphraseValue)
return ""
}
address_uncompressed := priv.ToAddressUncompressed()
if (address_uncompressed == address) {
return passphraseValue
}
return ""
}
I don't know what the problem can be, can anyone help me?
答案1
得分: 2
你需要使用"go get"命令安装依赖项。
根据错误消息所述,你没有安装依赖项。
仔细查看错误消息,你会发现有三个不同的错误。每个错误对应一个不属于Go标准库的包。
当你尝试导入一个不属于Go标准库的包时,Go编译器会在$GOROOT路径和$GOPATH路径下查找与你尝试导入的包名匹配的包。如果找不到,编译器就会抛出上面你看到的错误。正如@Adrian所说,你可以运行:
go get ./...
来自动下载所有的依赖项。
英文:
You need to install the dependencies using the "go get" command.
You don't have the dependencies installed, as stated in the error message.
Look a little closer at the error messages, you are getting three different errors. One for each package that is not part of the go standard libary.
When you try to import a package that is not part of the go standard library, the go compiler looks under the $GOROOT path and the $GOPATH path to try to find a package matching the name that you tried to import. If it is not found the compiler throws the error that you were seeing above. As @Adrian said, you can run:
go get ./...
<br>
to automatically download all of your dependencies.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论