Code Monkey home page Code Monkey logo

Comments (2)

aayushsinha44 avatar aayushsinha44 commented on May 26, 2024 4

While generating onion url you have to provide the private key. If you preserve the onion address by supplying same key.

Here _key is your key in string format.
key, err := ParseRsaPrivateKeyFromPemStr(_key)
onion, err = t.Listen(ctx, &tor.ListenConf{RemotePorts: []int{80}, LocalPort: goServerPort, Key: key})

For generating private key and storing it as string for later reference.

func GenerateKey() string {
key, err := rsa.GenerateKey(rand.Reader, 1024)
if err != nil {
return err.Error()
}
return ExportRsaPrivateKeyAsPemStr(key)
}

func ExportRsaPrivateKeyAsPemStr(privkey *rsa.PrivateKey) string {
privkey_bytes := x509.MarshalPKCS1PrivateKey(privkey)
privkey_pem := pem.EncodeToMemory(
&pem.Block{
Type: "RSA PRIVATE KEY",
Bytes: privkey_bytes,
},
)
return string(privkey_pem)
}

func ParseRsaPrivateKeyFromPemStr(privPEM string) (*rsa.PrivateKey, error) {
block, _ := pem.Decode([]byte(privPEM))
if block == nil {
return nil, errors.New("failed to parse PEM block containing the key")
}
priv, err := x509.ParsePKCS1PrivateKey(block.Bytes)
if err != nil {
return nil, err
}
return priv, nil
}

from go-libtor.

qwertyqop avatar qwertyqop commented on May 26, 2024

after trying to write a tor V3 address to the _key variable, i was having some issues
_key = "== ed25519v1-secret: "....
it returns: "panic: runtime error: invalid memory address or nil pointer dereference"
then it segfaults.
is there a similar function to ParseRsaPrivateKeyFromPemStr but for V3 addresses? i couldn't find anything in the documentation

from go-libtor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.