- 大論壇
- Taiwan
- 組鍵盤除了鑷子測試還要先燒機
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
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; |
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
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") |
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
@Data | |
@AllArgsConstructor | |
public class Response { | |
private String code; | |
private Map<String, Object> data; | |
private Long timestamp; | |
private String checksum; | |
} |
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
fun String.md5() = | |
MessageDigest.getInstance("MD5") | |
.also { | |
it.update(this.toByteArray(StandardCharsets.UTF_8)) | |
}.run { | |
this.digest().toHexString() | |
} | |
println("abc".md5()) |
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
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)) |
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
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))); | |
} |
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
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() |
OlderNewer