Created
February 17, 2021 06:22
-
-
Save Carlos-Augusto/22c21fedfe1389197d55288d2e2be93d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.bouncycastle.jce.provider.BouncyCastleProvider | |
import org.bouncycastle.util.Strings | |
import java.security.Security | |
import java.util.Base64 | |
import javax.crypto.Mac | |
import javax.crypto.spec.SecretKeySpec | |
Security.addProvider(new BouncyCastleProvider()) | |
val macKey = new SecretKeySpec( | |
Base64.getDecoder.decode("QwKFZpTiEcXnLdbbGEdzcO57/yoIVGOpixXfeKGLDdg="), // Secret | |
"HmacSHA256" | |
) | |
val data = Strings.toByteArray("Hello World") | |
val mac = Mac.getInstance("HmacSHA256", "BC") | |
mac.init(macKey) | |
mac.update(data) | |
Base64.getEncoder.encodeToString(mac.doFinal()) | |
//IFVv0O2lWoHNjEEsGcL9YOiaPNWkHIVkpCiiTKsp1ac= |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment