Last active
March 27, 2020 05:45
-
-
Save anny0739/fbc2d7a82a6da3dca0436a0f20f76f33 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 javax.crypto.Mac | |
import javax.crypto.spec.SecretKeySpec | |
import kotlin.experimental.and | |
fun main(args: Array<String>) { | |
val hmacFromKomoju = "06cb40bd7c630613e41f874296eddd0153d023857a76a9de52daad5da6c2bbe4" | |
val algorithm = "HmacSHA256" | |
val key = "secret Key" | |
val text = "?timestamp=1585286159&transaction%5Badditional_information%5D%5Bconfirmation_code%5D=&transaction%5Badditional_information%5D%5Bend_date%5D=1585493999&transaction%5Badditional_information%5D%5Bkonbini%5D=seven-eleven&transaction%5Badditional_information%5D%5Breceipt%5D=ecvtsmawjn&transaction%5Bamount%5D=1514&transaction%5Bcurrency%5D=JPY&transaction%5Bexternal_order_num%5D=924147676981943169&transaction%5Bgrand_total%5D=1704&transaction%5Bpayment_method%5D=konbini&transaction%5Bpayment_method_fee%5D=190&transaction%5Bstatus%5D=authorized&transaction%5Btax%5D=0&transaction%5Buuid%5D=0q9qy8kznsaj1w1jqnyiutonx" | |
// Encryption | |
val keySpec = SecretKeySpec(key.toByteArray(), algorithm) | |
val mac = Mac.getInstance(algorithm) | |
mac.init(keySpec) | |
val sign = mac.doFinal(text.toByteArray()) | |
.joinToString("") { String.format("%02x", it and 255.toByte()) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment