当前位置: 首页>>代码示例>>Scala>>正文


Scala Security类代码示例

本文整理汇总了Scala中java.security.Security的典型用法代码示例。如果您正苦于以下问题:Scala Security类的具体用法?Scala Security怎么用?Scala Security使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Security类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: Settings

//设置package包名称以及导入依赖的类
// Copyright (c) 2017 Grier Forensics. All Rights Reserved.

package com.grierforensics.greatdane.connector

import java.security.Security

import com.typesafe.config.ConfigFactory
import org.bouncycastle.jce.provider.BouncyCastleProvider

object Settings {

  private val config = {
    val cfg = ConfigFactory.load()
    cfg.getConfig("com.grierforensics.greatdane.connector")
  }

  // This must occur once, so this is a logical place to do it
  val SecurityProvider = new BouncyCastleProvider
  Security.addProvider(SecurityProvider)

  val Host: String = config.getString("host")
  val Port: Int = config.getInt("port")
  val ApiKey: String = config.getString("apiKey")

  case class ZoneFileDetails(origin: String, baseFile: String, outFile: String,
                             ttl: Long, writePeriod: Int)

  val ManageZone: Boolean = config.getBoolean("manageZone")

  val Zone = ZoneFileDetails(
    config.getString("zone.origin"),
    config.getString("zone.basefile"),
    config.getString("zone.outfile"),
    config.getLong("zone.ttl"),
    config.getInt("zone.write.period")
  )

  case class GeneratorDetails(keyAlgo: String, keyBits: Int, selfSign: Boolean,
                              signingKey: String, signingCert: String, signingAlgo: String,
                              expiryDays: Int)

  private val certs = config.getConfig("certificates")
  val Generator: Option[GeneratorDetails] = if (certs.getBoolean("generate")) {
    Some(
      GeneratorDetails(
        certs.getString("key.algorithm"),
        certs.getInt("key.bits"),

        certs.getBoolean("selfSign"),

        certs.getString("signing.key"),
        certs.getString("signing.certificate"),
        certs.getString("signing.algorithm"),

        certs.getInt("expiry.days")
      )
    )
  } else {
    None
  }
} 
开发者ID:grierforensics,项目名称:Great-DANE-Connector,代码行数:62,代码来源:Settings.scala

示例2: PublicKey

//设置package包名称以及导入依赖的类
package im.actor.server.api.rpc.service.auth

import org.bouncycastle.jce.provider.BouncyCastleProvider
import java.security.{ Security, MessageDigest }
import scala.annotation.tailrec

object PublicKey {
  Security.addProvider(new BouncyCastleProvider())

  def keyHash(pk: Array[Byte]): Long = {
    val md = MessageDigest.getInstance("SHA-256")
    val buf: Array[Byte] = md.digest(pk)
    val longSize = 8

    @tailrec
    def f(res: Long, index: Int): Long = {
      if (index == longSize) res
      else {
        val n = buf(index) ^ buf(index + longSize) ^ buf(index + longSize * 2) ^ buf(index + longSize * 3)
        f(((n & 0xffL) << (longSize - index - 1) * longSize) | res, index + 1)
      }
    }
    f(0L, 0)
  }
}

trait PublicKeyHelpers {
  def keyHash(pk: Array[Byte]) = PublicKey.keyHash(pk)
} 
开发者ID:wex5,项目名称:dangchat-server,代码行数:30,代码来源:PublicHeyHelpers.scala

示例3: HashImpl

//设置package包名称以及导入依赖的类
package one.lockstep.util.crypto

import java.security.Security
import javax.crypto.spec.SecretKeySpec

import one.lockstep.util._

class HashImpl private (name: String) extends Hash {

  private lazy val provider = {
    val preferredProviders = Seq("GmsCore_OpenSSL", "AndroidOpenSSL", "SUN")
    val providers = Security.getProviders(s"MessageDigest.$name")
    val filteredProviders = providers.filter(p => preferredProviders.contains(p.getName)).distinct
    filteredProviders.head
  }

  private def newInstance() = java.security.MessageDigest.getInstance(name, provider)
  override lazy val blockLength: Int = newInstance().getDigestLength*8
  override lazy val bitStrength: Int = blockLength/2

  override def apply(message: Bytes): Digest = Digest(newInstance().digest(message))
}

object HashImpl {
  val md5 = new HashImpl("MD5") { override lazy val bitStrength = 64 }
  val sha1 = new HashImpl("SHA-1") { override lazy val bitStrength = 80 }
  val sha256 = new HashImpl("SHA-256") { override lazy val bitStrength = 128 }
  val sha386 = new HashImpl("SHA-386") { override lazy val bitStrength = 192 }
  val sha512 = new HashImpl("SHA-512") { override lazy val bitStrength = 256 }
  private val members: Seq[Hash] = Seq(md5, sha1, sha256, sha386, sha512)
  def apply(l: Int): Hash =
    members.filter(_.bitStrength >= l).minBy(_.bitStrength)
} 
开发者ID:lockstep-one,项目名称:vault,代码行数:34,代码来源:HashImpl.scala

示例4: Hmac

//设置package包名称以及导入依赖的类
package one.lockstep.util.crypto

import java.security.Security
import javax.crypto.spec.SecretKeySpec

import one.lockstep.util._


class Hmac private (serviceName: String) extends Mac with Cryptosystem {

  private lazy val provider = {
    val preferredProviders = Seq("GmsCore_OpenSSL", "AndroidOpenSSL", "SunJCE")
    val providers = Security.getProviders(s"Mac.$serviceName")
    val filteredProviders = providers.filter(p => preferredProviders.contains(p.getName)).distinct
    filteredProviders.head
  }

  private def newInstance() = javax.crypto.Mac.getInstance(serviceName, provider)
  override lazy val blockLength: Int = newInstance().getMacLength*8
  override lazy val bitStrength: Int = blockLength/2
  override lazy val keyLength: Int = blockLength/2

  override def apply(secretKey: SecretKey): Bytes ? MacTag = {
    bytes ?
      val hmac = newInstance()
      val key = new SecretKeySpec(secretKey.raw, serviceName)
      hmac.init(key)
      MacTag(hmac.doFinal(bytes))
  }

  override def keygen(): SecretKey =
    SecretKey(random.bits(keyLength).bytes)

  override def validate(secretKey: SecretKey): Boolean =
    secretKey.bitLength == keyLength
}

object Hmac {
  val md5 = new Hmac("HmacMD5") { override lazy val bitStrength = 64 }
  val sha1 = new Hmac("HmacSHA1") { override lazy val bitStrength = 80 }
  val sha256 = new Hmac("HmacSHA256") { override lazy val bitStrength = 128 }
  val sha386 = new Hmac("HmacSHA386") { override lazy val bitStrength = 192 }
  val sha512 = new Hmac("HmacSHA512") { override lazy val bitStrength = 256 }
  private val members: Seq[Hmac] = Seq(md5, sha1, sha256, sha386, sha512)
  def apply(l: Int): Hmac =
    members.filter(_.bitStrength >= l).minBy(_.bitStrength)
} 
开发者ID:lockstep-one,项目名称:vault,代码行数:48,代码来源:Hmac.scala

示例5: JWTPublicKeyProviderImpl

//设置package包名称以及导入依赖的类
package access

import java.security.spec.{ECPoint, ECPublicKeySpec}
import java.security.{KeyFactory, PublicKey, Security}

import com.google.inject.Inject
import org.bouncycastle.jce.ECNamedCurveTable
import org.bouncycastle.jce.spec.ECNamedCurveSpec
import play.api.Configuration

class JWTPublicKeyProviderImpl @Inject()(configuration: Configuration) extends JWTPublicKeyProvider {

  override def publicKey: PublicKey = {
    val xRaw: String = configuration.getString("accessService.X").getOrElse("")
    val yRaw: String = configuration.getString("accessService.Y").getOrElse("")
    val X = BigInt(xRaw, 16)
    val Y = BigInt(yRaw, 16)
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider())
    val curveParams = ECNamedCurveTable.getParameterSpec("P-521")
    val curveSpec =
      new ECNamedCurveSpec("P-521", curveParams.getCurve, curveParams.getG, curveParams.getN, curveParams.getH)
    val publicSpec = new ECPublicKeySpec(new ECPoint(X.underlying(), Y.underlying()), curveSpec)
    KeyFactory.getInstance("ECDSA", "BC").generatePublic(publicSpec)
  }

} 
开发者ID:shafiquejamal,项目名称:api-gateway-template,代码行数:27,代码来源:JWTPublicKeyProviderImpl.scala

示例6: JWTPrivateKeyProviderImpl

//设置package包名称以及导入依赖的类
package access

import java.security.spec.ECPrivateKeySpec
import java.security.{KeyFactory, PrivateKey, Security}

import com.google.inject.Inject
import org.bouncycastle.jce.ECNamedCurveTable
import org.bouncycastle.jce.spec.ECNamedCurveSpec
import play.api.Configuration

class JWTPrivateKeyProviderImpl @Inject()(configuration: Configuration) extends JWTPrivateKeyProvider {

  override def privateKey: PrivateKey = {
    val sRaw: String = configuration.getString("accessService.S").getOrElse("")
    val S = BigInt(sRaw, 16)
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider())
    val curveParams = ECNamedCurveTable.getParameterSpec("P-521")
    val curveSpec =
      new ECNamedCurveSpec("P-521", curveParams.getCurve, curveParams.getG, curveParams.getN, curveParams.getH)
    val privateSpec = new ECPrivateKeySpec(S.underlying(), curveSpec)
    KeyFactory.getInstance("ECDSA", "BC").generatePrivate(privateSpec)
  }

} 
开发者ID:shafiquejamal,项目名称:api-gateway-template,代码行数:25,代码来源:JWTPrivateKeyProviderImpl.scala

示例7: Main

//设置package包名称以及导入依赖的类
package crypto

import java.security.Security
import crypto.Crypto._
import org.bouncycastle.jce.provider.BouncyCastleProvider

object Main extends App {

  Security.addProvider(new BouncyCastleProvider())

  val rootCN = mkX500Name(
    "Weyland-Yutani Class 3 Public Primary Certification Authority - G5",
    Vector("(c) 2016 Weyland-Yutani, Inc. - For authorized use only",
      "Weyland-Yutani Trust Network"),
    "Weyland-Yutani, Inc.",
    "US"
  )
  val intCN = mkX500Name(
    "Weyland-Yutani Class 3 EV SSL CA - G3",
    Vector("Weyland-Yutani Trust Network"),
    "Weyland-Yutani Corporation",
    "US"
  )
  val clientCN = mkX500Name2(
    "*.compute-1.amazonaws.com",Vector("Enterprise IT"),
    "Weyland-Yutani, Inc",
    "1 Weyland-Yutani Way",
    "New York",
    "New York",
    "10003",
    "US",
    1
  )

  val rootKey = genRSA(RSA2048)
  val rootCert = createRootCACert(rootKey.getPublic, 1L, rootKey.getPrivate, rootCN, 365*20)
  write(rootKey.getPrivate.getEncoded, "root_rsa.der")
  write(rootKey.getPublic.getEncoded, "root_pub.der")
  write(rootCert.getEncoded, "root.der")

  val intKey = genRSA(RSA2048)
  val intCert = createCACert(intKey.getPublic, 1L, rootKey.getPrivate, rootCN, intCN, 365*2)
  write(intKey.getPrivate.getEncoded, "int_rsa.der")
  write(intKey.getPublic.getEncoded, "int_pub.der")
  write(intCert.getEncoded, "int.der")

  val clientKey = genRSA(RSA2048)
  val clientCert = createClientCert(clientCN, 1L, clientKey.getPublic, intCert, intKey.getPrivate, intKey.getPublic, "*.compute-1.amazonaws.com", Vector("localhost"), Vector("127.0.0.1"), 365*2)
  write(clientKey.getPrivate.getEncoded, "localhost_rsa.der")
  write(clientKey.getPublic.getEncoded, "localhost_pub.der")
  write(clientCert.getEncoded, "localhost.der")


} 
开发者ID:jasonmar,项目名称:CertificateAuthorityInABox,代码行数:55,代码来源:Main.scala

示例8: RSAKeyGenerator

//设置package包名称以及导入依赖的类
package allawala.chassis.util

import java.io.{File, FileOutputStream, OutputStreamWriter}
import java.nio.file.Paths
import java.security.{Key, KeyPair, KeyPairGenerator, Security}

import com.typesafe.scalalogging.StrictLogging
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.bouncycastle.util.io.pem.{PemObject, PemWriter}


object RSAKeyGenerator extends StrictLogging {
  private val KeySize = 2048
  private val homeDir = System.getProperty("user.home")

  private class PemFile(val key: Key, val description: String) {
    private val pemObject = new PemObject(description, key.getEncoded)

    def write(file: File): Unit = {
      val pemWriter = new PemWriter(new OutputStreamWriter(new FileOutputStream(file)))
      try {
        pemWriter.writeObject(this.pemObject)
      }
      finally {
        pemWriter.close()
      }
    }
  }

  private def generateKeyPair(): KeyPair = {
    val generator = KeyPairGenerator.getInstance("RSA", "BC")
    generator.initialize(KeySize)
    val keyPair = generator.generateKeyPair
    keyPair
  }

  private def writePem(key: Key, description: String, filename: String): Unit = {
    val path = Paths.get(homeDir, filename)
    val file = path.toFile
    val pemFile = new PemFile(key, description)
    pemFile.write(file)
    logger.debug(s"Writing $description to $path/$filename")
  }

  def generate(): Unit = {
    Security.addProvider(new BouncyCastleProvider)

    val keyPair = generateKeyPair()
    val privateKey = keyPair.getPrivate
    val publicKey = keyPair.getPublic

    writePem(privateKey, "RSA PRIVATE KEY","id_rsa")
    writePem(publicKey, "RSA PUBLIC KEY", "id_rsa.pub")
  }
} 
开发者ID:allawala,项目名称:service-chassis,代码行数:56,代码来源:RSAKeyGenerator.scala

示例9: App

//设置package包名称以及导入依赖的类
package de.m7w3.signal

import java.security.Security

import de.m7w3.signal.controller.{DeviceRegistration, UnlockDB}
import org.whispersystems.libsignal.logging.SignalProtocolLoggerProvider

import scalafx.application.JFXApp
import scalafx.application.JFXApp.PrimaryStage
import scalafx.scene.Scene

object App {
  val NAME = "signal-desktop"
  val VERSION = "0.0.1"
  val AUTHOR = "motherflippers"
}

object Main extends JFXApp {
  Security.insertProviderAt(new org.bouncycastle.jce.provider.BouncyCastleProvider(), 1)
  SignalProtocolLoggerProvider.setProvider(new ProtocolLogger())


  val signalDesktopConfig = Config.optionParser.parse(parameters.raw, Config.SignalDesktopConfig())
  signalDesktopConfig.foreach { config =>
    val ctxBuilder = ContextBuilder(config)
    val root = if (ctxBuilder.profileDirExists && ctxBuilder.profileIsInitialized) {
      UnlockDB(ctxBuilder)
    } else {
      // show welcome and registration screen
      DeviceRegistration.load(ctxBuilder)
    }
    stage = new PrimaryStage {
      title = "Welcome"
      scene = new Scene(root)
    }
  }

  override def stopApp(): Unit = {
    // cleanup shit
    ApplicationContext.getCurrent.foreach(_.close())
    println("bye!")
    super.stopApp()
  }
} 
开发者ID:ayoub-benali,项目名称:signal-desktop-client,代码行数:45,代码来源:Main.scala

示例10: JWTPublicKeyProviderImpl

//设置package包名称以及导入依赖的类
package com.eigenroute.authentication

import java.security.spec.{ECPoint, ECPublicKeySpec}
import java.security.{KeyFactory, PublicKey, Security}

import com.typesafe.config.ConfigFactory
import org.bouncycastle.jce.ECNamedCurveTable
import org.bouncycastle.jce.spec.ECNamedCurveSpec

class JWTPublicKeyProviderImpl extends JWTPublicKeyProvider {

  val configuration = ConfigFactory.load()

  override def publicKey: PublicKey = {
    val xRaw: String = configuration.getString("eigenrouteAuthenticatedAction.publicKey.X")
    val yRaw: String = configuration.getString("eigenrouteAuthenticatedAction.publicKey.Y")
    val X = BigInt(xRaw, 16)
    val Y = BigInt(yRaw, 16)
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider())
    val curveParams = ECNamedCurveTable.getParameterSpec("P-521")
    val curveSpec =
      new ECNamedCurveSpec("P-521", curveParams.getCurve, curveParams.getG, curveParams.getN, curveParams.getH)
    val publicSpec = new ECPublicKeySpec(new ECPoint(X.underlying(), Y.underlying()), curveSpec)
    KeyFactory.getInstance("ECDSA", "BC").generatePublic(publicSpec)
  }

} 
开发者ID:shafiquejamal,项目名称:eigenroute-authenticated-action,代码行数:28,代码来源:JWTPublicKeyProviderImpl.scala

示例11: JWTPrivateKeyProviderImpl

//设置package包名称以及导入依赖的类
package com.eigenroute.authentication

import java.security.spec.ECPrivateKeySpec
import java.security.{KeyFactory, PrivateKey, Security}

import com.typesafe.config.ConfigFactory
import org.bouncycastle.jce.ECNamedCurveTable
import org.bouncycastle.jce.spec.ECNamedCurveSpec

class JWTPrivateKeyProviderImpl extends JWTPrivateKeyProvider {

  val configuration = ConfigFactory.load()

  override def privateKey: PrivateKey = {
    val sRaw: String = configuration.getString("eigenrouteAuthenticatedAction.privateKey.S")
    val S = BigInt(sRaw, 16)
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider())
    val curveParams = ECNamedCurveTable.getParameterSpec("P-521")
    val curveSpec =
      new ECNamedCurveSpec("P-521", curveParams.getCurve, curveParams.getG, curveParams.getN, curveParams.getH)
    val privateSpec = new ECPrivateKeySpec(S.underlying(), curveSpec)
    KeyFactory.getInstance("ECDSA", "BC").generatePrivate(privateSpec)
  }

} 
开发者ID:shafiquejamal,项目名称:eigenroute-authenticated-action,代码行数:26,代码来源:JWTPrivateKeyProviderImpl.scala


注:本文中的java.security.Security类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。