本文整理汇总了Scala中org.apache.commons.codec.digest.DigestUtils类的典型用法代码示例。如果您正苦于以下问题:Scala DigestUtils类的具体用法?Scala DigestUtils怎么用?Scala DigestUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DigestUtils类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: PasswordCipher
//设置package包名称以及导入依赖的类
package model.auth
import java.util.UUID
import org.apache.commons.codec.digest.DigestUtils
object PasswordCipher {
val STRETCH_LOOP_COUNT = 1000
def hashAndStretch(plain: String, salt: String, loopCnt: Int): String = {
var hashed: String = ""
(1 to STRETCH_LOOP_COUNT).foreach(i =>
hashed = DigestUtils.sha256Hex(hashed + plain + salt)
)
hashed
}
def createPasswordSalt(): String = {
DigestUtils.sha256Hex(UUID.randomUUID().toString)
}
}
开发者ID:nimmortal,项目名称:todo-list-play-auth-slick,代码行数:23,代码来源:PasswordCipher.scala
示例2: WriteRemoteFile
//设置package包名称以及导入依赖的类
package org.scalawag.jibe.mandate.command
import java.io.{ByteArrayInputStream, File, FileInputStream, InputStream}
import org.apache.commons.codec.digest.DigestUtils
case class WriteRemoteFile(remotePath: File, content: FileContent) extends UnitCommand
trait FileContent {
// must be closed by caller
def openInputStream: InputStream
def length: Long
lazy val md5 = {
val fis = openInputStream
try {
DigestUtils.md5Hex(fis).toLowerCase
} finally {
fis.close()
}
}
}
object FileContent {
implicit def apply(f: File) = new FileContentFromFile(f)
implicit def apply(a: Array[Byte]) = new FileContentFromArray(a)
implicit def apply(s: String) = new FileContentFromArray(s.getBytes) // TODO: charset
}
case class FileContentFromFile(file: File) extends FileContent {
override def openInputStream = new FileInputStream(file)
override def length = file.length
override val toString = s"file($file)"
}
case class FileContentFromArray(bytes: Seq[Byte]) extends FileContent {
override def openInputStream = new ByteArrayInputStream(bytes.toArray)
override def length = bytes.length
override val toString = s"array(${bytes.length} bytes)"
}
开发者ID:scalawag,项目名称:jibe,代码行数:42,代码来源:FileCommands.scala
示例3: Signer
//设置package包名称以及导入依赖的类
package com.wix.pay.dengionline
import com.wix.pay.dengionline.model.Fields
import org.apache.commons.codec.digest.DigestUtils
/**
* From the document (sic.):
* 1. Signature (sign) is the HEX representation of the SHA1-hash of a specially-formed line (string like
* "35d11d32141601a6c10703f06591a16bb20c41ef").
* 2. Encoding of signatured string is UTF-8.
* 3. All the query parameters are sorted in ascending order parameter names. The parameter names in lower case, and it
* is always the rows that meet the following regular expression: [a-z_]{1}[a-z0-9_]
* 4. All settings will be drawn into a single string using the separator character between them.
* 5. parameters are separated with semicolon ";".
* 6. Each parameter is attached in the form of substring "should have param_name:param_value" where should have
* param_name - name parameter, param_value - the value of the parameter, followed by a colon ":" - internal separator.
* 7. Parameters whose value is the empty string "" - skipped.
* 8. If parameter value is an array, its elements are sorted in ascending order of their keys and drawn to the delimiter
* character. Elements of arrays (nested arrays) are ignored and the delimiter character is dont needed.
* 9. In the of the line which is made using via separator character is appended salt (salt) site; if signatured string
* is empty, then the delimiter character before the salt of the site is not intended, however, this is a exceptional
* case, which in practice cannot be used.
* 10. To avoid double signing parameters with names "sign" and "signature" are always excluded from the signature.
*/
object Signer {
private val ignoredFields = Set(Fields.sign, Fields.signature)
def calculateSignature(params: Map[String, String], salt: String): String = {
val paramsStr = params.toSeq
.filterNot {
case (name, value) => ignoredFields.contains(name) || value.isEmpty
}
.sorted
.map {
case (name, value) => s"$name:$value"
}
.mkString(";")
val stringForSignature = s"$paramsStr;$salt"
DigestUtils.sha1Hex(stringForSignature)
}
}
开发者ID:wix,项目名称:libpay-dengionline,代码行数:44,代码来源:Signer.scala
示例4: Attachment
//设置package包名称以及导入依赖的类
package redmine4s.api.model
import java.io.InputStream
import org.apache.commons.codec.digest.DigestUtils
import org.joda.time.DateTime
import redmine4s.Redmine
case class Attachment(id: Long, fileName: String, fileSize: Long, contentType: Option[String], description: String, contentUrl: String, author: (Long, String), createdOn: DateTime, redmine: Redmine) {
lazy val content: Array[Byte] = redmine.getAttachmentContent(this)
lazy val digest: String = DigestUtils.md5Hex(content)
lazy val diskDirectory = createdOn.toString("yyyy/MM")
lazy val diskFilename = {
def letterCheck(str: String): Boolean = str.forall { c => c.isLower || c.isUpper || c.isDigit || "_-.".contains(c) }
val header = createdOn.toString("yyMMddHHmmss_")
if (letterCheck(fileName)) {
header + fileName
} else fileName.split('.').lastOption match {
case Some(ext) if letterCheck(ext) =>
header + DigestUtils.md5Hex(fileName) + "." + ext
case _ =>
header + DigestUtils.md5Hex(fileName)
}
}
}
case class UploadFile(filename: String, contentType: String, content: Either[InputStream, Array[Byte]])
case class UploadedFile(filename: String, contentType: String, token: String)
开发者ID:tomingtoming,项目名称:redmine4s,代码行数:30,代码来源:Attachment.scala
示例5: Template
//设置package包名称以及导入依赖的类
package de.frosner.broccoli.models
import java.util.regex.Pattern
import org.apache.commons.codec.digest.DigestUtils
import play.api.libs.json._
import play.api.libs.functional.syntax._
import scala.collection.mutable.ArrayBuffer
import ParameterInfo.parameterInfoWrites
case class Template(id: String, template: String, description: String, parameterInfos: Map[String, ParameterInfo])
extends Serializable {
@transient
lazy val parameters: Set[String] = {
val matcher = Template.TemplatePattern.matcher(template)
var variables = ArrayBuffer[String]()
while (matcher.find()) {
variables += matcher.group(1)
}
val uniqueVariables = variables.toSet
require(
uniqueVariables.contains("id"),
s"There needs to be an 'id' field in the template for Broccoli to work. Parameters defined: ${uniqueVariables}")
uniqueVariables
}
@transient
lazy val version: String = DigestUtils.md5Hex(template.trim() + "_" + parameterInfos.toString)
}
object Template {
val TemplatePattern = Pattern.compile("\\{\\{([A-Za-z][A-Za-z0-9\\-\\_\\_]*)\\}\\}")
implicit val templateApiWrites: Writes[Template] = (
(JsPath \ "id").write[String] and
(JsPath \ "description").write[String] and
(JsPath \ "parameters").write[Set[String]] and
(JsPath \ "parameterInfos").write[Map[String, ParameterInfo]] and
(JsPath \ "version").write[String]
)((template: Template) =>
(template.id, template.description, template.parameters, template.parameterInfos, template.version))
implicit val templatePersistenceReads: Reads[Template] = Json.reads[Template]
implicit val templatePersistenceWrites: Writes[Template] = Json.writes[Template]
}
开发者ID:FRosner,项目名称:cluster-broccoli,代码行数:53,代码来源:Template.scala
示例6: NormalizationHandler
//设置package包名称以及导入依赖的类
package com.fustigatedcat.heystk.engine.normalization
import java.io.ByteArrayInputStream
import java.util.zip.GZIPInputStream
import com.fustigatedcat.heystk.common.normalization.Normalization
import com.fustigatedcat.heystk.engine.queue.RabbitQueue
import org.apache.commons.codec.binary.Base64
import org.apache.commons.codec.digest.DigestUtils
import org.apache.commons.io.IOUtils
import org.json4s.native.JsonMethods.parse
import org.slf4j.LoggerFactory
object NormalizationHandler {
val logger = LoggerFactory.getLogger(this.getClass)
implicit val formats = org.json4s.DefaultFormats
def checksum(string : String) : String = {
DigestUtils.sha256Hex(string)
}
def unzip(string : String) : String = {
val arr = Base64.decodeBase64(string)
val gis = new GZIPInputStream(new ByteArrayInputStream(arr))
IOUtils.toString(gis, "UTF-8")
}
def handle(string : String, chksm : String) = {
val body = unzip(string)
if(checksum(body) == chksm) {
// write normalization to temp DB and post to Queue for needs processing
parse(unzip(string)).extract[List[Normalization]].par.foreach(RabbitQueue.postToProcess)
} else {
logger.error(s"Invalid checksum ${checksum(body)} != $chksm")
}
}
}
开发者ID:fustigatedcat,项目名称:heystk,代码行数:42,代码来源:NormalizationHandler.scala
示例7: MD5Functions
//设置package包名称以及导入依赖的类
package com.destrys
import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
import org.apache.spark.Logging
import org.apache.spark.rdd.RDD
import org.apache.commons.codec.digest.DigestUtils
import org.apache.commons.codec.digest.DigestUtils._
import org.apache.spark.HashPartitioner
import java.security.MessageDigest
class MD5Functions(rdd: RDD[String]) extends Logging with Serializable {
def md5_partitioned(parts: Int = 100): String = {
val partitioner = new HashPartitioner(parts)
val output = rdd.
map(x => (x, 1)).
repartitionAndSortWithinPartitions(partitioner).
map(_._1).
mapPartitions(x => Iterator(x.foldLeft(getMd5Digest())(md5))).
map(x => new java.math.BigInteger(1, x.digest()).toString(16)).
collect().
sorted.
foldLeft(getMd5Digest())(md5)
val checksum = new java.math.BigInteger(1, output.digest()).toString(16)
return(checksum)
}
def md5(prev: MessageDigest, in2: String): MessageDigest = {
val b = in2.getBytes("UTF-8")
prev.update(b, 0, b.length)
prev
}
}
object RddMD5 {
implicit def rddToMD5Functions(rdd: RDD[String]) = new MD5Functions(rdd)
def main(args: Array[String]) {
// Configuration
val conf = new SparkConf().setAppName("CatExample") // Creates empty SparkConf and sets the AppName
val sc = new SparkContext(conf) // Creates a new SparkContext
val text = sc.textFile(args(0)) // Reads a textfile, in local-mode the default is file:///
// in yarn-mode, the default is hdfs:///
text.md5_partitioned(10)
}
}
开发者ID:destrys,项目名称:spark-md5,代码行数:54,代码来源:rddmd5.scala
示例8: DatabaseAuth
//设置package包名称以及导入依赖的类
package com.malliina.logstreams.db
import java.sql.SQLException
import com.malliina.logstreams.auth.UserError.{AlreadyExists, DoesNotExist}
import com.malliina.logstreams.auth.UserService
import com.malliina.logstreams.db.Mappings.{password, username}
import com.malliina.play.auth.BasicCredentials
import com.malliina.play.models.{Password, Username}
import org.apache.commons.codec.digest.DigestUtils
import slick.jdbc.H2Profile.api._
import scala.concurrent.Future
object DatabaseAuth {
def apply(userDB: UserDB): DatabaseAuth = new DatabaseAuth(userDB)
def hash(username: Username, password: Password): Password =
Password(DigestUtils.md5Hex(username.name + ":" + password.pass))
}
class DatabaseAuth(db: UserDB) extends UserService {
import UserDB.users
implicit val ec = db.ec
override def add(creds: BasicCredentials): Future[Either[AlreadyExists, Unit]] = {
db.run(users += DataUser(creds.username, hash(creds))).map(_ => Right(())) recover {
case sqle: SQLException if sqle.getMessage contains "primary key violation" =>
Left(AlreadyExists(creds.username))
}
}
override def update(creds: BasicCredentials): Future[Either[DoesNotExist, Unit]] =
withUser(creds.username)(_.map(_.passHash).update(hash(creds)))
override def remove(user: Username): Future[Either[DoesNotExist, Unit]] =
withUser(user)(_.delete)
override def isValid(creds: BasicCredentials): Future[Boolean] =
db.run(userQuery(creds.username).filter(_.passHash === hash(creds)).exists.result)
override def all(): Future[Seq[Username]] = db.runQuery(users.map(_.user))
private def withUser[T](user: Username)(code: Query[Users, DataUser, Seq] => DBIOAction[Int, NoStream, _]) =
db.run(code(userQuery(user))).map(c => analyzeRowCount(c, user))
private def userQuery(user: Username): Query[Users, DataUser, Seq] = users.filter(_.user === user)
private def analyzeRowCount(rowCount: Int, username: Username): Either[DoesNotExist, Unit] =
if (rowCount == 0) Left(DoesNotExist(username)) else Right(())
private def hash(creds: BasicCredentials) = DatabaseAuth.hash(creds.username, creds.password)
}
开发者ID:malliina,项目名称:logstreams,代码行数:54,代码来源:DatabaseAuth.scala
示例9: Application
//设置package包名称以及导入依赖的类
package controllers
import org.apache.commons.codec.digest.DigestUtils
import play.api.Logger
import play.api.mvc._
import play.api.libs.json.Json._
object Application extends Controller {
def index = Action { implicit request =>
Ok(currentApi)
}
private def currentApi(implicit request: RequestHeader) = {
toJson(Map(
"root" -> request.uri
))
}
def get(signature: String, timestamp: String, nonce: String,echostr: String) = Action { implicit request =>
//????????? (print)
// val logger = Logger(this.getClass)
// logger.debug(request.rawQueryString)
println(signature,timestamp,nonce,echostr)
val token:String= "tokenfortest"
val tmpStr = (DigestUtils.sha1Hex(Seq(token, timestamp, nonce).sorted.mkString)).toString
println(tmpStr)
if( tmpStr == signature ){
// logger.info("return ok")
Ok(echostr)
}else{
// logger.error("not match signature")
BadRequest
}
}
}
开发者ID:alisonyang,项目名称:playWeisin,代码行数:42,代码来源:Application.scala
示例10: SimpleCachePlainResultWithETag
//设置package包名称以及导入依赖的类
package webby.commons.cache
import java.time.{LocalDateTime, ZoneId}
import com.google.common.net.HttpHeaders
import org.apache.commons.codec.digest.DigestUtils
import webby.api.mvc._
import webby.commons.time.StdDates
class SimpleCachePlainResultWithETag(expireMillis: Long, cacheLoader: => PlainResult)
extends SimpleCache[(PlainResult, String)](expireMillis, {
val result: PlainResult = cacheLoader
val eTag: String = DigestUtils.md5Hex(result.body)
result.withHeader(HttpHeaders.ETAG, eTag) -> eTag
}) {
def eTagFrom(result: PlainResult): String = DigestUtils.md5Hex(result.body)
def handle(req: RequestHeader): PlainResult = {
// ??????? ?????????, ???????? ?? ?????? ?? E-TAG'?
req.headers.get(HttpHeaders.IF_NONE_MATCH) match {
case Some(ifNoneMatch) =>
val (result, eTag) = get
if (ifNoneMatch == eTag) Results.NotModified
else result
case None =>
// ?????, ?????????, ???????????? ?? ?????? if-modified-since
req.headers.get(HttpHeaders.IF_MODIFIED_SINCE) match {
case Some(ifModifiedStr) =>
val ifModified: Long =
try StdDates.toMillis(LocalDateTime.parse(ifModifiedStr, StdDates.httpDateFormat), ZoneId.systemDefault())
catch {case e: Exception => throw ResultException(get._1)}
getIfModifiedSince(ifModified) match {
case Some(v) => v._1
case None => Results.NotModified
}
case None => get._1
}
}
}
def action = SimpleAction {implicit req =>
handle(req)
}
}
开发者ID:citrum,项目名称:webby,代码行数:49,代码来源:SimpleCache.scala
示例11: Extensions
//设置package包名称以及导入依赖的类
import org.apache.commons.codec.digest.DigestUtils
object Extensions {
implicit def conversion(msg: String) = new Binary(msg)
class Binary(msg: String) {
def b : String = {
val bytes = msg.getBytes()
val bStr = new StringBuilder()
for (b <- bytes) {
var tmp: Int = b
var i = 0
while(i < 8) {
bStr.append(if ((tmp & 128) == 0) 0 else 1)
tmp <<= 1
i +=1
}
// bStr.append(' ');
}
bStr.toString()
}
}
implicit def sha[T](data: T) = new SHA(data)
class SHA[T](data: T) {
implicit def sha256 : String = data match {
case _:Array[Byte] => DigestUtils.sha256Hex(data.asInstanceOf[Array[Byte]])
case _:String => DigestUtils.sha256Hex(data.asInstanceOf[String])
case _ => null.asInstanceOf[String]
}
}
implicit def transform[T](data: List[T]) = new Transform(data)
class Transform[T](data: List[T]) {
implicit def leaves : List[String] = {
var nodes = for(e <- data) yield e.sha256
if (nodes.size % 2 == 1) {
nodes = nodes :+ nodes.last
}
nodes
}
}
}
开发者ID:nvxtien,项目名称:merkle-tree-scala,代码行数:45,代码来源:helper.scala
注:本文中的org.apache.commons.codec.digest.DigestUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论