• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java IPad类的典型用法和代码示例

java 1次浏览

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

IPad类属于gnu.javax.crypto.pad包,在下文中一共展示了IPad类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getInstance

点赞 3

import gnu.javax.crypto.pad.IPad; //导入依赖的package包/类
/**
 * Returns an instance of a SASL-SRP CALG implementation.
 *
 * @param algorithm the name of the symmetric cipher algorithm.
 * @return an instance of this object.
 */
static synchronized CALG getInstance(final String algorithm)
{
  final IBlockCipher cipher = CipherFactory.getInstance(algorithm);
  final int blockSize = cipher.defaultBlockSize();
  final int keySize = cipher.defaultKeySize();
  final Cascade ofbCipher = new Cascade();
  IMode ofbMode = ModeFactory.getInstance(Registry.OFB_MODE,
                                          cipher,
                                          blockSize);
  Stage modeStage = Stage.getInstance(ofbMode, Direction.FORWARD);
  final Object modeNdx = ofbCipher.append(modeStage);
  final IPad pkcs7 = PadFactory.getInstance(Registry.PKCS7_PAD);
  final Assembly asm = new Assembly();
  asm.addPreTransformer(Transformer.getCascadeTransformer(ofbCipher));
  asm.addPreTransformer(Transformer.getPaddingTransformer(pkcs7));
  return new CALG(blockSize, keySize, modeNdx, asm);
}
 

开发者ID:vilie,
项目名称:javify,
代码行数:24,
代码来源:CALG.java

示例2: getInstance

点赞 3

import gnu.javax.crypto.pad.IPad; //导入依赖的package包/类
/**
 * Returns an instance of a SASL-SRP CALG implementation.
 * 
 * @param algorithm the name of the symmetric cipher algorithm.
 * @return an instance of this object.
 */
static synchronized CALG getInstance(final String algorithm)
{
  final IBlockCipher cipher = CipherFactory.getInstance(algorithm);
  final int blockSize = cipher.defaultBlockSize();
  final int keySize = cipher.defaultKeySize();
  final Cascade ofbCipher = new Cascade();
  IMode ofbMode = ModeFactory.getInstance(Registry.OFB_MODE,
                                          cipher,
                                          blockSize);
  Stage modeStage = Stage.getInstance(ofbMode, Direction.FORWARD);
  final Object modeNdx = ofbCipher.append(modeStage);
  final IPad pkcs7 = PadFactory.getInstance(Registry.PKCS7_PAD);
  final Assembly asm = new Assembly();
  asm.addPreTransformer(Transformer.getCascadeTransformer(ofbCipher));
  asm.addPreTransformer(Transformer.getPaddingTransformer(pkcs7));
  return new CALG(blockSize, keySize, modeNdx, asm);
}
 

开发者ID:nmldiegues,
项目名称:jvm-stm,
代码行数:24,
代码来源:CALG.java

示例3: decrypt

点赞 2

import gnu.javax.crypto.pad.IPad; //导入依赖的package包/类
public void decrypt(char[] password) throws IllegalArgumentException,
    WrongPaddingException
{
  if (Configuration.DEBUG)
    log.entering(this.getClass().getName(), "decrypt");
  if (isMasked() && payload != null)
    {
      long tt = -System.currentTimeMillis();
      IMode mode = getMode(password, IMode.DECRYPTION);
      IPad padding = PadFactory.getInstance("PKCS7");
      padding.init(mode.currentBlockSize());
      byte[] buf = new byte[payload.length];
      int count = 0;
      while (count + mode.currentBlockSize() <= payload.length)
        {
          mode.update(payload, count, buf, count);
          count += mode.currentBlockSize();
        }
      int padlen = padding.unpad(buf, 0, buf.length);
      setMasked(false);
      int len = buf.length - padlen;
      ByteArrayInputStream baos = new ByteArrayInputStream(buf, 0, len);
      DataInputStream in = new DataInputStream(baos);
      try
        {
          decodeEnvelope(in);
        }
      catch (IOException ioe)
        {
          throw new IllegalArgumentException("decryption failed");
        }
      tt += System.currentTimeMillis();
      log.fine("Decrypted in " + tt + "ms.");
    }
  else if (Configuration.DEBUG)
    log.fine("Skip decryption; " + (isMasked() ? "null payload" : "unmasked"));
  if (Configuration.DEBUG)
    log.exiting(this.getClass().getName(), "decrypt");
}
 

开发者ID:vilie,
项目名称:javify,
代码行数:40,
代码来源:PasswordEncryptedEntry.java

示例4: decrypt

点赞 2

import gnu.javax.crypto.pad.IPad; //导入依赖的package包/类
public void decrypt(byte[] key, byte[] iv) throws IllegalArgumentException,
    WrongPaddingException
{
  if (! isMasked() || payload == null)
    return;
  IMode mode = getMode(key, iv, IMode.DECRYPTION);
  IPad padding = null;
  padding = PadFactory.getInstance("PKCS7");
  padding.init(mode.currentBlockSize());
  byte[] buf = new byte[payload.length];
  int count = 0;
  for (int i = 0; i < payload.length; i++)
    {
      mode.update(payload, count, buf, count);
      count += mode.currentBlockSize();
    }
  int padlen = padding.unpad(buf, 0, buf.length);
  int len = buf.length - padlen;
  DataInputStream in = new DataInputStream(new ByteArrayInputStream(buf, 0, len));
  try
    {
      decodeEnvelope(in);
    }
  catch (IOException ioe)
    {
      throw new IllegalArgumentException("decryption failed");
    }
  setMasked(false);
  payload = null;
}
 

开发者ID:vilie,
项目名称:javify,
代码行数:31,
代码来源:EncryptedEntry.java

示例5: encrypt

点赞 2

import gnu.javax.crypto.pad.IPad; //导入依赖的package包/类
public void encrypt(byte[] key, byte[] iv) throws IOException
{
  IMode mode = getMode(key, iv, IMode.ENCRYPTION);
  IPad pad = PadFactory.getInstance("PKCS7");
  pad.init(mode.currentBlockSize());
  ByteArrayOutputStream bout = new ByteArrayOutputStream(1024);
  DataOutputStream out2 = new DataOutputStream(bout);
  for (Iterator it = entries.iterator(); it.hasNext();)
    {
      Entry entry = (Entry) it.next();
      entry.encode(out2);
    }
  byte[] plaintext = bout.toByteArray();
  byte[] padding = pad.pad(plaintext, 0, plaintext.length);
  payload = new byte[plaintext.length + padding.length];
  byte[] lastBlock = new byte[mode.currentBlockSize()];
  int l = mode.currentBlockSize() - padding.length;
  System.arraycopy(plaintext, plaintext.length - l, lastBlock, 0, l);
  System.arraycopy(padding, 0, lastBlock, l, padding.length);
  int count = 0;
  while (count + mode.currentBlockSize() < plaintext.length)
    {
      mode.update(plaintext, count, payload, count);
      count += mode.currentBlockSize();
    }
  mode.update(lastBlock, 0, payload, count);
}
 

开发者ID:vilie,
项目名称:javify,
代码行数:28,
代码来源:EncryptedEntry.java

示例6: getPaddingTransformer

点赞 2

import gnu.javax.crypto.pad.IPad; //导入依赖的package包/类
public static final Transformer getPaddingTransformer(IPad padding)
{
  return new PaddingTransformer(padding);
}
 

开发者ID:vilie,
项目名称:javify,
代码行数:5,
代码来源:Transformer.java

示例7: PaddingTransformer

点赞 2

import gnu.javax.crypto.pad.IPad; //导入依赖的package包/类
PaddingTransformer(IPad padding)
{
  super();

  this.delegate = padding;
}
 

开发者ID:vilie,
项目名称:javify,
代码行数:7,
代码来源:PaddingTransformer.java

示例8: encrypt

点赞 2

import gnu.javax.crypto.pad.IPad; //导入依赖的package包/类
public void encrypt(char[] password) throws IOException
{
  if (Configuration.DEBUG)
    log.entering(this.getClass().getName(), "encrypt", String.valueOf(password));
  long tt = -System.currentTimeMillis();
  long t1 = -System.currentTimeMillis();
  byte[] salt = new byte[8];
  PRNG.getInstance().nextBytes(salt);
  t1 += System.currentTimeMillis();
  if (Configuration.DEBUG)
    log.fine("-- Generated salt in " + t1 + "ms.");
  properties.put("salt", Util.toString(salt));
  IMode mode = getMode(password, IMode.ENCRYPTION);
  IPad pad = PadFactory.getInstance("PKCS7");
  pad.init(mode.currentBlockSize());
  ByteArrayOutputStream bout = new ByteArrayOutputStream(1024);
  DataOutputStream out2 = new DataOutputStream(bout);
  for (Iterator it = entries.iterator(); it.hasNext();)
    {
      Entry entry = (Entry) it.next();
      if (Configuration.DEBUG)
        log.fine("-- About to encode one " + entry);
      t1 = -System.currentTimeMillis();
      entry.encode(out2);
      t1 += System.currentTimeMillis();
      if (Configuration.DEBUG)
        log.fine("-- Encoded an Entry in " + t1 + "ms.");
    }
  byte[] plaintext = bout.toByteArray();
  byte[] padding = pad.pad(plaintext, 0, plaintext.length);
  payload = new byte[plaintext.length + padding.length];
  byte[] lastBlock = new byte[mode.currentBlockSize()];
  int l = mode.currentBlockSize() - padding.length;
  System.arraycopy(plaintext, plaintext.length - l, lastBlock, 0, l);
  System.arraycopy(padding, 0, lastBlock, l, padding.length);
  int count = 0;
  while (count + mode.currentBlockSize() < plaintext.length)
    {
      mode.update(plaintext, count, payload, count);
      count += mode.currentBlockSize();
    }
  mode.update(lastBlock, 0, payload, count);
  setMasked(true);
  tt += System.currentTimeMillis();
  if (Configuration.DEBUG)
    {
      log.fine("Encrypted in " + tt + "ms.");
      log.exiting(this.getClass().getName(), "encrypt");
    }
}
 

开发者ID:vilie,
项目名称:javify,
代码行数:51,
代码来源:PasswordEncryptedEntry.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)