Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6324219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:39:48+00:00 2026-05-24T16:39:48+00:00

When I try to run the following code (I’m trying to encrypt the byte

  • 0

When I try to run the following code (I’m trying to encrypt the byte array representation of a string, using AES in CFB mode) I get an invalid memory address or nil pointer dereference error, on the line sEnc.XORKeyStream(msgB, msgB). The documentation says the source and destination for XORKeyStream can be the same byte array (also tried using a separate destination, but no dice), but I can’t figure out what’s causing the error. I’m using the latest version of the Go App Engine SDK on OS X Lion.

Since at this point I’m still trying to get the code to simply encrypt something, I’m just generating a random key and not bothering to store it yet.

func generateKey(w http.ResponseWriter, r *http.Request) {
    key := make([]byte, 32)
    n, err := rand.Read(key)
    err = err
    if(err != nil) {
        fmt.Fprint(w, err)
        return
    }
    if(n != 32) {
        fmt.Fprint(w, "Not enough bytes read.")
        return
    }
    c, err := aes.NewCipher(key)
    if(err != nil) {
        fmt.Fprint(w, err)
    }

    iv := make([]byte, 32)
    n, err = rand.Read(iv)
    err = err
    if(err != nil) {
        fmt.Fprint(w, err)
        return
    }
    if(n != 32) {
        fmt.Fprint(w, "Not enough bytes read.")
        return
    }

    sEnc := cipher.NewCFBEncrypter(c, iv)

    msg := "text to be encrypted"
    msgR := strings.NewReader(msg)
    msgB := make([]byte, msgR.Len())
    n, err = msgR.Read(msgB)
    if(err != nil) {
        fmt.Fprint(w, err)
        return
    }
    if(n == 0) {
        fmt.Fprint(w, "No bytes read.")
        return
    }
    fmt.Fprint(w, msgB)
    fmt.Fprint(w, "<br>")
    sEnc.XORKeyStream(msgB, msgB)
    fmt.Fprint(w, msgB)
}

The error messages:

2011/08/15 15:15:58 http: panic serving : runtime error: invalid
memory address or nil pointer dereference runtime.panic
/private/tmp/appengine/google_appengine/goroot/src/pkg/runtime/proc.c:1041
runtime.panicstring
/private/tmp/appengine/google_appengine/goroot/src/pkg/runtime/runtime.c:116
runtime.sigpanic
/private/tmp/appengine/google_appengine/goroot/src/pkg/runtime/darwin/thread.c:470
server.generateKey server/server.go:66 http.HandlerFunc·ServeHTTP
/private/tmp/appengine/google_appengine/goroot/src/pkg/http/server.go:589
http.*ServeMux·ServeHTTP
/private/tmp/appengine/google_appengine/goroot/src/pkg/http/server.go:790
appengine_internal.handleFilteredHTTP
/private/tmp/appengine/google_appengine/goroot/src/pkg/appengine_sdk/go_appengine_sdk/appengine_internal/api_dev.go:58
http.HandlerFunc·ServeHTTP
/private/tmp/appengine/google_appengine/goroot/src/pkg/http/server.go:589
http.*conn·serve
/private/tmp/appengine/google_appengine/goroot/src/pkg/http/server.go:555
runtime.goexit
/private/tmp/appengine/google_appengine/goroot/src/pkg/runtime/proc.c:178
INFO 2011-08-15 15:15:58,310 dev_appserver.py:4248] “GET
/genkey/aes256 HTTP/1.1” 500 –

I’ve posted the rest of the code to paste bin, but it’s just the includes/init function, nothing all that interesting.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:39:49+00:00Added an answer on May 24, 2026 at 4:39 pm

    sEnc is nil as a result of an error. For cipher.NewCFBEncrypter, “the iv must be the same length as the Block’s block.” The AES block size is 128 bits or 16 bytes? For example,

    iv := make([]byte, c.BlockSize())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I try to run the following code (from the REPL) in Clojure: (dotimes
When I try to run the following code it always spits out the hex
The following code will output the command string I wish to run: [string] $SourceRepo=C:\inetpub\wwwroot\Spyda\
I'm trying to get the Score_Waarde value from my database using the following code
When I run the following code, I keep getting a glibc detected error when
When I try to run a .NET assembly ( boo.exe ) from a network
Every time I try to run a small application that uses a Derby DB
When I try to run a particular stored procedure on my MS SQL 2005
whenever I try to run something in Java, Eclipse changes into the PHP perspective.
I get a generic failure when I try to run: saslpasswd2 username This was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.