Can anyone know about encryption decryption using crypto package base64 with same key?

Can anyone know about encryption decryption using crypto package base64 with same key ??

base64 is not an encryption it is an encoding., and it does not have any notion of a key. Can you please elaborate on your question?

Yes , i know base64 is encoding but i use this function for getting and inserting document in my database but when i use this give me error in unexpected EOF , so i debug this and found key is mismatched in both function usage so can any idea how to set similar key in both function???
`func encrypt(keyString string, stringToEncrypt string) (encryptedString string) {
// convert key to bytes
key, _ := hex.DecodeString(keyString)
plaintext := byte(stringToEncrypt)

//Create a new Cipher Block from the key
block, err := aes.NewCipher(key)
if err != nil {
	panic(err.Error())
}

// The IV needs to be unique, but not secure. Therefore it's common to
// include it at the beginning of the ciphertext.
ciphertext := make([]byte, aes.BlockSize+len(plaintext))
iv := ciphertext[:aes.BlockSize]
if _, err := io.ReadFull(rand.Reader, iv); err != nil {
	panic(err)
}

stream := cipher.NewCFBEncrypter(block, iv)
stream.XORKeyStream(ciphertext[aes.BlockSize:], plaintext)

// convert to base64
return base64.URLEncoding.EncodeToString(ciphertext)

}

// decrypt from base64 to decrypted string
func decrypt(keyString string, stringToDecrypt string) string {
key, _ := hex.DecodeString(keyString)
ciphertext, _ := base64.URLEncoding.DecodeString(stringToDecrypt)

block, err := aes.NewCipher(key)
if err != nil {
	panic(err)
}

// The IV needs to be unique, but not secure. Therefore it's common to
// include it at the beginning of the ciphertext.
if len(ciphertext) < aes.BlockSize {
	panic("ciphertext too short")
}
iv := ciphertext[:aes.BlockSize]
ciphertext = ciphertext[aes.BlockSize:]

stream := cipher.NewCFBDecrypter(block, iv)

// XORKeyStream can work in-place if the two arguments are the same.
stream.XORKeyStream(ciphertext, ciphertext)

return fmt.Sprintf("%s", ciphertext)

}

`

I didnt do a deep Analysis, though on a quick glance it seems as if you aren’t prepending the IV to the output when encrypting, but try to read it from the input when decrypting.

Yeah, using the crypto package and base64 for encryption and decryption with the same key is totally doable. It’s like speaking in code, but with a twist! Just make sure you keep that key safe and sound, like your secret stash of snacks.

1 Like

Yeah, using the crypto package and base64 for encryption and decryption with the same key is totally doable. It’s like speaking in code, but with a twist! Just make sure you keep that key safe and sound, like your secret stash of snacks.
If you’re still curious about it, I’ve got a suggestion for you. Dive into some online tutorials or hit up forums where crypto enthusiasts hang out. You’ll find a ton of helpful info there.
Oh, and speaking of diving into new things, if you’re interested in exploring the world of cryptocurrency, you can sign up for Binance or use 바이낸스 가입

  • crypto package: This is a built-in Python module for cryptographic operations. It provides various algorithms for encryption and decryption.
  • Base64 encoding/decoding: This is a technique for encoding binary data into a text format using characters from A-Z, a-z, 0-9, +, and /. It’s reversible, allowing you to decode the encoded text back to its original binary form.