Examples of SecretKeySpec


Examples of javax.crypto.spec.SecretKeySpec

   * @param iv      加密矢量,增加加密强度
   * @return
   */
  public static byte[] AESDecrypt(byte[] encrypted, byte[] key, byte[] iv) {
    try {
          SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
          IvParameterSpec ivSpec = new IvParameterSpec(iv);
          Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
          cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivSpec);
          return cipher.doFinal(encrypted);
    } catch(InvalidKeyException e) {
View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

      SRPParameters params = session.getParameters();
      Set privateCredentials = subject.getPrivateCredentials();
      privateCredentials.add(params);
      if( params.cipherAlgorithm != null )
      {
         SecretKeySpec secretKey = new SecretKeySpec(sessionKey, params.cipherAlgorithm);
         privateCredentials.add(secretKey);
      }
      else
      {
         privateCredentials.add(sessionKey);
View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

            byte[] sessionKey = session.getSessionKey();
            SRPParameters params = session.getParameters();
            Set privateCredentials = subject.getPrivateCredentials();
            if( params.cipherAlgorithm != null )
            {
               SecretKeySpec secretKey = new SecretKeySpec(sessionKey, params.cipherAlgorithm);
               privateCredentials.remove(secretKey);
            }
            else
            {
               privateCredentials.remove(sessionKey);
View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

   {
      login("jduke", "secret".toCharArray());
      System.out.println("Logged into server");
      byte[] kbytes = client.getSessionKey();
      System.out.println("Session key size = "+kbytes.length);
      SecretKeySpec clientKey = new SecretKeySpec(kbytes, "Blowfish");
      System.out.println("clientKey");
     
      Cipher cipher = Cipher.getInstance("Blowfish");
      cipher.init(Cipher.ENCRYPT_MODE, clientKey);
      SealedObject msg = new SealedObject("This is a secret", cipher);
     
      // Now use the server key to decrypt the msg
      byte[] skbytes = server.session.getSessionKey();
      SecretKeySpec serverKey = new SecretKeySpec(skbytes, "Blowfish");
      Cipher scipher = Cipher.getInstance("Blowfish");
      scipher.init(Cipher.DECRYPT_MODE, serverKey);
      String theMsg = (String) msg.getObject(scipher);
      System.out.println("Decrypted: "+theMsg);
View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

      System.out.println("key.Encoded Size = "+kbytes.length);
     
      SecureRandom rnd = SecureRandom.getInstance("SHA1PRNG");
      BigInteger bi = new BigInteger(320, rnd);
      byte[] k2bytes = bi.toByteArray();
      SecretKeySpec keySpec = new SecretKeySpec(k2bytes, "Blowfish");
      System.out.println("key2.Algorithm = "+key.getAlgorithm());
      System.out.println("key2.Format = "+key.getFormat());
      System.out.println("key2.Encoded Size = "+kbytes.length);
   }
View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

   * @throws IOException if an error occurs
   */
  public static byte[] computeRFC2104HMAC(byte[] data, byte[] key) throws IOException {
     
      try {
          SecretKeySpec signingKey = new SecretKeySpec(key, "HmacSHA1");
   
          Mac mac = Mac.getInstance("HmacSHA1");
          mac.init(signingKey);
   
          byte[] rawHmac = mac.doFinal(data);
View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

        }
      }
      key = (new DESedeKeySpec(desedekey)).getKey();
    }

    SecretKey secretKey = new SecretKeySpec(key,algorithm);

    /* DES in ECB mode does not require any parameters */
    if (mode.equals("ECB")) {
      _cipher.init(opmode, secretKey);

View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

     * @throws IOException if an error occurs
     */
    public static byte[] computeRFC2104HMAC(byte[] data, byte[] key) throws IOException {
       
        try {
            SecretKeySpec signingKey = new SecretKeySpec(key, "HmacSHA1");
   
            Mac mac = Mac.getInstance("HmacSHA1");
            mac.init(signingKey);
   
            byte[] rawHmac = mac.doFinal(data);
View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

   * @throws IOException if an error occurs
   */
  public static byte[] computeRFC2104HMAC(byte[] data, byte[] key) throws IOException {
     
      try {
          SecretKeySpec signingKey = new SecretKeySpec(key, "HmacSHA1");
   
          Mac mac = Mac.getInstance("HmacSHA1");
          mac.init(signingKey);
   
          byte[] rawHmac = mac.doFinal(data);
View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

     * @throws IOException if an error occurs
     */
    public static byte[] computeRFC2104HMAC(byte[] data, byte[] key) throws IOException {
       
        try {
            SecretKeySpec signingKey = new SecretKeySpec(key, "HmacSHA1");
   
            Mac mac = Mac.getInstance("HmacSHA1");
            mac.init(signingKey);
   
            byte[] rawHmac = mac.doFinal(data);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.