the Encryption in Java is by importing javax.crypto.Cipher, sun.misc.BASE64Decoder, sun.misc.BASE64Encoder and javax/crypto/SecretKey.
I did a lot research on those algorithms to understand the specific standards to make sure every step is the same in Java and Golang.
"=="
inputs: key: T3-Arghbegrgg455dfer4g== text: 123456789012345 output: golang: 07vl02WwI8dApjYI161TrQ== java: B9E8aoCd+fYQBkKbqCS3lA==
Please help to find out the reason behind the difference! Thanks!
The java code using
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
byte[] stringBytes = message.getBytes("UTF8");
byte[] raw = cipher.doFinal(stringBytes);
BASE64Encoder encoder = new BASE64Encoder();
String base64 = encoder.encode(raw);
return base64;
In Golang
block, err := aes.NewCipher(key)
if err != nil {
return "",err
}
content := []byte(src)
ecb := NewECBEncrypter(block)
content = PKCS5Padding(content, block.BlockSize())
crypted := make([]byte, len(content))
ecb.CryptBlocks(crypted, content)
finalMsg := base64.StdEncoding.EncodeToString(crypted)
return finalMsg,nil