Home  >  Article  >  Backend Development  >  Here are a few potential titles, playing with different tones and targeted audiences: Direct and Informative: * How to Encrypt with Golang and Decrypt with Java or Scala (using AES-CFB) * Cross-Lang

Here are a few potential titles, playing with different tones and targeted audiences: Direct and Informative: * How to Encrypt with Golang and Decrypt with Java or Scala (using AES-CFB) * Cross-Lang

Susan Sarandon
Susan SarandonOriginal
2024-10-26 11:36:02960browse

Here are a few potential titles, playing with different tones and targeted audiences:

Direct and Informative:

* How to Encrypt with Golang and Decrypt with Java or Scala (using AES-CFB)
* Cross-Language Encryption: Golang Encryption & Java/Scala Decrypt

AES Encryption in Golang and Decryption in Java

In this article, we will explore the implementation of AES encryption in Golang and demonstrate how to decrypt the encrypted text in Java.

Golang Encryption Function

The Golang encryption function converts a plain text string into encrypted ciphertext using the Advanced Encryption Standard (AES) with Cipher Block Feed (CFB) mode. It generates a random initialization vector (IV), encrypts the plaintext, and returns the encrypted text as a base64-encoded string.

Java Decryption Function

The Java decryption function takes the encrypted text and the encryption key as input. It decodes the base64-encoded data, extracts the IV, and initializes the AES/CFB/NoPadding cipher. Subsequently, it decrypts the ciphertext to retrieve the original plaintext, which is then returned as a string.

Scala Decryption Function

The provided Scala decryption function is similar to the Java function. It uses the Base64 URL decoder to decode the input text, initializes the AES/CFB/NoPadding cipher, extracts the IV, and decrypts the ciphertext. However, it originally employed Hex.decodeHex, which should be replaced with the Base64 URL decoder for accurate decryption.

Example Usage

You can use the provided Golang encryption function to encrypt text in Golang. The resulting ciphertext can be passed to the Java or Scala decryption functions to retrieve the original plaintext. For instance, consider the input text "test text 123." The encryption function in Golang will produce "c1bpFhxn74yzHQs-vgLcW6E5yL8zJfgceEQgYl0=" as the encrypted ciphertext. The Java or Scala decryption functions can then be used to recover the original plaintext "test text 123."

The above is the detailed content of Here are a few potential titles, playing with different tones and targeted audiences: Direct and Informative: * How to Encrypt with Golang and Decrypt with Java or Scala (using AES-CFB) * Cross-Lang. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn