Skip to content

Instantly share code, notes, and snippets.

View Jian-Min-Huang's full-sized avatar
🔥
Go Go Go !

黃健旻 Vincent Huang Jian-Min-Huang

🔥
Go Go Go !
View GitHub Profile
public class Response {
private String code;
private Map<String, Object> data;
private Long timestamp;
private String checksum;
public Response(String code, Map<String, Object> data, Long timestamp, String checksum) {
this.code = code;
this.data = data;
data class Response(
var code: String,
var data: Map<String, Any>,
var timestamp: Long,
var checksum: String
)
fun main() {
val response = Response("T001", mapOf("a" to 100), Date().time, "317d069fe45debda190c3f5822f16484")
@Data
@AllArgsConstructor
public class Response {
private String code;
private Map<String, Object> data;
private Long timestamp;
private String checksum;
}
fun String.md5() =
MessageDigest.getInstance("MD5")
.also {
it.update(this.toByteArray(StandardCharsets.UTF_8))
}.run {
this.digest().toHexString()
}
println("abc".md5())
fun String.aesDecrypt(transformation: String = "AES/CBC/PKCS7PADDING", key: String, iv: String) =
also {
Security.addProvider(BouncyCastleProvider())
}.let {
Cipher.getInstance(transformation)
}.also {
it.init(
Cipher.DECRYPT_MODE,
SecretKeySpec(key.toByteArray(StandardCharsets.UTF_8), "AES"),
IvParameterSpec(iv.toByteArray(StandardCharsets.UTF_8))
String aesDecrypt(String cipherText, String key, String iv) {
Security.addProvider(new BouncyCastleProvider());
Cipher cipher = Cipher.getInstance(transformation);
cipher.init(Cipher.DECRYPT_MODE,
new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES"),
new IvParameterSpec(iv.getBytes(StandardCharsets.UTF_8)));
return new String(cipher.doFinal(hexString2ByteArray(cipherText)));
}
fun blockingMvc() =
run {
// action 1, cost 100ms
val delay100res = getBlockingResponse(100)!!["totalTimeMillis"].parseLong()
// action 2, cost 200ms
val delay200res = getBlockingResponse(200)!!["totalTimeMillis"].parseLong()
// action 3, need return value from action 1 and 2, cost 300ms
val delay300req = getBlockingResponse(delay100res + delay200res)!!["totalTimeMillis"].parseLong()