當前位置: 首頁>>代碼示例>>Java>>正文


Java Cipher.UNWRAP_MODE屬性代碼示例

本文整理匯總了Java中javax.crypto.Cipher.UNWRAP_MODE屬性的典型用法代碼示例。如果您正苦於以下問題:Java Cipher.UNWRAP_MODE屬性的具體用法?Java Cipher.UNWRAP_MODE怎麽用?Java Cipher.UNWRAP_MODE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在javax.crypto.Cipher的用法示例。


在下文中一共展示了Cipher.UNWRAP_MODE屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: engineGetOutputSize

public int engineGetOutputSize(int inputLen)
{
    int len1, len2, len3;

    len1 = engine.getMac().getMacSize();

    if (key != null)
    {
        len2 = 1 + 2 * (((ECKey)key).getParameters().getCurve().getFieldSize() + 7) / 8;
    }
    else
    {
        throw new IllegalStateException("cipher not initialised");
    }

    if (engine.getCipher() == null)
    {
        len3 = inputLen;
    }
    else if (state == Cipher.ENCRYPT_MODE || state == Cipher.WRAP_MODE)
    {
        len3 = engine.getCipher().getOutputSize(inputLen);
    }
    else if (state == Cipher.DECRYPT_MODE || state == Cipher.UNWRAP_MODE)
    {
        len3 = engine.getCipher().getOutputSize(inputLen - len1 - len2);
    }
    else
    {
        throw new IllegalStateException("cipher not initialised");
    }

    if (state == Cipher.ENCRYPT_MODE || state == Cipher.WRAP_MODE)
    {
        return buffer.size() + len1 + len2 + len3;
    }
    else if (state == Cipher.DECRYPT_MODE || state == Cipher.UNWRAP_MODE)
    {
        return buffer.size() - len1 - len2 + len3;
    }
    else
    {
        throw new IllegalStateException("cipher not initialised");
    }

}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:46,代碼來源:IESCipher.java

示例2: engineGetOutputSize

protected int engineGetOutputSize(
    int     inputLen) 
{
    if (state == Cipher.ENCRYPT_MODE || state == Cipher.WRAP_MODE)
    {
        return buffer.size() + inputLen + 20; /* SHA1 MAC size */
    }
    else if (state == Cipher.DECRYPT_MODE || state == Cipher.UNWRAP_MODE)
    {
        return buffer.size() + inputLen - 20;
    }
    else
    {
        throw new IllegalStateException("cipher not initialised");
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:16,代碼來源:CipherSpi.java

示例3: engineGetOutputSize

protected int engineGetOutputSize(
    int     inputLen)
{
    if (state == Cipher.ENCRYPT_MODE || state == Cipher.WRAP_MODE)
    {
        return buffer.size() + inputLen + 20; /* SHA1 MAC size */
    }
    else if (state == Cipher.DECRYPT_MODE || state == Cipher.UNWRAP_MODE)
    {
        return buffer.size() + inputLen - 20;
    }
    else
    {
        throw new IllegalStateException("cipher not initialised");
    }
}
 
開發者ID:BiglySoftware,項目名稱:BiglyBT,代碼行數:16,代碼來源:JCEIESCipher.java

示例4: engineGetOutputSize

public int engineGetOutputSize(int inputLen)
{
    int len1, len2, len3;

    len1 = engine.getMac().getMacSize();

    if (key != null)
    {
        len2 = ((DHKey)key).getParams().getP().bitLength() / 8 + 1;
    }
    else
    {
        throw new IllegalStateException("cipher not initialised");
    }

    if (engine.getCipher() == null)
    {
        len3 = inputLen;
    }
    else if (state == Cipher.ENCRYPT_MODE || state == Cipher.WRAP_MODE)
    {
        len3 = engine.getCipher().getOutputSize(inputLen);
    }
    else if (state == Cipher.DECRYPT_MODE || state == Cipher.UNWRAP_MODE)
    {
        len3 = engine.getCipher().getOutputSize(inputLen - len1 - len2);
    }
    else
    {
        throw new IllegalStateException("cipher not initialised");
    }

    if (state == Cipher.ENCRYPT_MODE || state == Cipher.WRAP_MODE)
    {
        return buffer.size() + len1 + len2 + len3;
    }
    else if (state == Cipher.DECRYPT_MODE || state == Cipher.UNWRAP_MODE)
    {
        return buffer.size() - len1 - len2 + len3;
    }
    else
    {
        throw new IllegalStateException("IESCipher not initialised");
    }

}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:46,代碼來源:IESCipher.java

示例5: engineInit

public void engineInit(
      int                     opmode,
      Key                     key,
      AlgorithmParameterSpec  params,
      SecureRandom            random)
  throws InvalidKeyException, InvalidAlgorithmParameterException
  {
      if (!(key instanceof IESKey))
      {
          throw new InvalidKeyException("must be passed IE key");
      }

      if (params == null && (opmode == Cipher.ENCRYPT_MODE || opmode == Cipher.WRAP_MODE))
      {
          //
          // if nothing is specified we set up for a 128 bit mac, with
          // 128 bit derivation vectors.
          //
          byte[]  d = new byte[16];
          byte[]  e = new byte[16];

          if (random == null)
          {
              random = new SecureRandom();
          }

          random.nextBytes(d);
          random.nextBytes(e);

          params = new IESParameterSpec(d, e, 128);
      }
      else if (!(params instanceof IESParameterSpec))
      {
          throw new InvalidAlgorithmParameterException("must be passed IES parameters");
      }

      IESKey       ieKey = (IESKey)key;

      CipherParameters pubKey;
      CipherParameters privKey;

      if (ieKey.getPublic() instanceof JCEECPublicKey)
      {
          pubKey = ECUtil.generatePublicKeyParameter(ieKey.getPublic());
          privKey = ECUtil.generatePrivateKeyParameter(ieKey.getPrivate());
      }
      else
      {
          pubKey = DHUtil.generatePublicKeyParameter(ieKey.getPublic());
          privKey = DHUtil.generatePrivateKeyParameter(ieKey.getPrivate());
      }

      this.engineParams = (IESParameterSpec)params;

      IESParameters       p = new IESParameters(engineParams.getDerivationV(), engineParams.getEncodingV(), engineParams.getMacKeySize());

      this.state = opmode;

      buffer.reset();

      switch (opmode)
      {
      case Cipher.ENCRYPT_MODE:
case Cipher.WRAP_MODE:
          cipher.init(true, privKey, pubKey, p);
          break;
      case Cipher.DECRYPT_MODE:
case Cipher.UNWRAP_MODE:
          cipher.init(false, privKey, pubKey, p);
          break;
      default:
          System.out.println("eeek!");
      }
  }
 
開發者ID:BiglySoftware,項目名稱:BiglyBT,代碼行數:74,代碼來源:JCEIESCipher.java


注:本文中的javax.crypto.Cipher.UNWRAP_MODE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。