Problem with rsa library

Hello everyone,
I have a very strange problem with rsa library.
I write a blockchain on Go and I have different localhosts connected with each other. So localhost1 sends the data, localhost2 encrypts the data and then localhost3 asks for data, so localhost2 has to decrypt it back.

I have the classic decrypt function:
infoSign, err:=rsa.DecryptPKCS1v15(rng,private,[]byte(hash))

So it kinda “dies” on the last step, doesn’t even go to check if the error is nil and so on. I run the process several times, sometimes it works, sometimes it looks like it is in an infinite cycle that influences on localhost3 and localhost2.
I know that it is a very messy explanation but maybe someone got the same problem and knows the solution?
Will appreciate any help. Thank you.

1 Like

Welcome to the community @Betty_Rain!

It would be helpful to see some more code.
You can enclose code into blocks here using the snippet at the bottom.

It’s also helpful if we can run the code in at They made it very easy to save and share a link to any kind of Go code.

Keep in mind that if you need to call data from disk the code in the Playground will not run. (As well as some other functions like those in the os and net packages)

```go type code here```

The word “go” after the first three back-ticks enables syntax highlighting.

1 Like

Thank you!
The project is big and it will be hard to send you the whole code with api and so on.
But not working part which is connected with rsa:

func DecryptInfo(hash []byte, privateKey []byte) string {
	rng := rand.Reader
	private := BytesToPrivateKey(privateKey)
	infoSign, err := rsa.DecryptPKCS1v15(rng, private, []byte(hash)) //Here the process "dies", it like does the infinite cycle without going to next step
	if err != nil {
		return ""
	return string(infoSign)

So, I call this function in another class like this:

decoded := datadApps.DecryptInfo(valueJson, privateKey)

where valueJson is an encrypted byte array

1 Like

Solved it, the problem was in memory.
It works when I empty the garbage collector by




Glad you got it figured out and thanks for sharing the solution!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.