增加String的MD5算法,修改登录借口

This commit is contained in:
2020-05-21 13:54:02 +08:00
parent 648a2384c4
commit 98b4dc639c
3 changed files with 51 additions and 19 deletions

View File

@@ -1,9 +1,32 @@
package com.synebula.gaea.extension
import java.math.BigInteger
import java.security.MessageDigest
import java.security.NoSuchAlgorithmException
/**
* 首字母小写
*/
fun String.firstCharLowerCase(): String {
if (Character.isLowerCase(this.elementAt(0)))
return this
return if (Character.isLowerCase(this.elementAt(0)))
this
else
return StringBuilder().append(Character.toLowerCase(this.elementAt(0)))
StringBuilder().append(Character.toLowerCase(this.elementAt(0)))
.append(this.substring(1)).toString()
}
}
/**
* 获取字符串的MD值
*/
fun String.toMd5(): String {
val secretBytes = try {
MessageDigest.getInstance("md5").digest(this.toByteArray())
} catch (e: NoSuchAlgorithmException) {
throw RuntimeException("没有这个md5算法")
}
var md5code = BigInteger(1, secretBytes).toString(16)
for (i in 0 until 32 - md5code.length) {
md5code = "0$md5code"
}
return md5code
}