Go语言:编译过程中出现错误

huangapple go评论79阅读模式
英文:

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 &quot;github.com/vsergeev/btckeygenie/btckey&quot; 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 &quot;golang.org/x/crypto/pbkdf2&quot; 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 &quot;golang.org/x/crypto/scrypt&quot; 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 (
    &quot;golang.org/x/crypto/pbkdf2&quot;
	&quot;golang.org/x/crypto/scrypt&quot;
	&quot;bytes&quot;
	&quot;crypto/sha256&quot;
	&quot;fmt&quot;
	&quot;time&quot;
	&quot;os&quot;
	&quot;math/rand&quot;
	&quot;github.com/vsergeev/btckeygenie/btckey&quot;
)

const letterBytes = &quot;0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;
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 := &quot;&quot;
	
	if len(os.Args) &gt;= 2 {
		address = os.Args[1]
		if len(os.Args) == 3 {
			saltValue = os.Args[2]
		} else {
			saltValue = &quot;&quot;;
		}
	} else {
		fmt.Printf(&quot;Usage: %s [Address] [Salt - optional]\n\n&quot;, os.Args[0])
		os.Exit(0)
	}
	
	fmt.Printf(&quot;Using address \&quot;%s\&quot; and salt \&quot;%s\&quot;\n&quot;, address, saltValue)
	
	tries := 0
	start := time.Now()
	for {
		passphraseValue := random(r, 8)
		result := bruteforce(passphraseValue, saltValue, address);
		if result != &quot;&quot; {
			fmt.Printf(&quot;Found! Passphrase %s\n&quot;, passphraseValue)
			os.Exit(0)
		} else {
			tries += 1
			fmt.Printf(&quot;\rTried %d passphrases in %s [last passphrase: %s]&quot;, 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, &quot;\x01&quot;)
    salt := fmt.Sprint(saltValue, &quot;\x01&quot;)
    key, _ := scrypt.Key([]byte(pass), []byte(salt), 262144, 8, 1, 32)
    pass = fmt.Sprint(passphraseValue, &quot;\x02&quot;)
    salt = fmt.Sprint(saltValue, &quot;\x02&quot;)
    key2 := pbkdf2.Key([]byte(pass), []byte(salt), 65536, 32, sha256.New)

    var result bytes.Buffer
    for i := 0; i &lt; len(key); i++ {
        result.WriteByte(key[i] ^ key2[i])
    }

	err = priv.FromBytes(result.Bytes())
	if err != nil {
		fmt.Printf(&quot;Error importing private key: %s [%s]\n&quot;, err, passphraseValue)
		return &quot;&quot;
	}
	
	address_uncompressed := priv.ToAddressUncompressed()
	
	if (address_uncompressed == address) {
		return passphraseValue
	}
	
	return &quot;&quot;
}

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.

huangapple
  • 本文由 发表于 2017年6月24日 02:11:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/44727616.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定