Java 类org.bouncycastle.crypto.paddings.ISO10126d2Padding 实例源码

项目:vsDiaryWriter    文件:BlockCiphers.java   
private static void initBlockCipherPaddings() {
    blockCipherPadding.put("ISO10126d2Padding", ISO10126d2Padding.class);
    blockCipherPadding.put("ISO7816d4Padding", ISO7816d4Padding.class);
    blockCipherPadding.put("PKCS7Padding", PKCS7Padding.class);
    blockCipherPadding.put("TBCPadding", TBCPadding.class);
    blockCipherPadding.put("X923Padding", X923Padding.class);
    blockCipherPadding.put("ZeroBytePadding", ZeroBytePadding.class);
}
项目:ipack    文件:BaseBlockCipher.java   
protected void engineSetPadding(
    String  padding)
throws NoSuchPaddingException
{
    String  paddingName = Strings.toUpperCase(padding);

    if (paddingName.equals("NOPADDING"))
    {
        if (cipher.wrapOnNoPadding())
        {
            cipher = new BufferedGenericBlockCipher(new BufferedBlockCipher(cipher.getUnderlyingCipher()));
        }
    }
    else if (paddingName.equals("WITHCTS"))
    {
        cipher = new BufferedGenericBlockCipher(new CTSBlockCipher(cipher.getUnderlyingCipher()));
    }
    else
    {
        padded = true;

        if (isAEADModeName(modeName))
        {
            throw new NoSuchPaddingException("Only NoPadding can be used with AEAD modes.");
        }
        else if (paddingName.equals("PKCS5PADDING") || paddingName.equals("PKCS7PADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher());
        }
        else if (paddingName.equals("ZEROBYTEPADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new ZeroBytePadding());
        }
        else if (paddingName.equals("ISO10126PADDING") || paddingName.equals("ISO10126-2PADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new ISO10126d2Padding());
        }
        else if (paddingName.equals("X9.23PADDING") || paddingName.equals("X923PADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new X923Padding());
        }
        else if (paddingName.equals("ISO7816-4PADDING") || paddingName.equals("ISO9797-1PADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new ISO7816d4Padding());
        }
        else if (paddingName.equals("TBCPADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new TBCPadding());
        }
        else
        {
            throw new NoSuchPaddingException("Padding " + padding + " unknown.");
        }
    }
}
项目:gwt-crypto    文件:PaddingTest.java   
public void performTest()
{
    SecureRandom    rand = new SecureRandom(new byte[20]);

    rand.setSeed(System.currentTimeMillis());

    testPadding(new PKCS7Padding(), rand,
                                Hex.decode("ffffff0505050505"),
                                Hex.decode("0000000004040404"));

    PKCS7Padding padder = new PKCS7Padding();
    try
    {
        padder.padCount(new byte[8]);

        fail("invalid padding not detected");
    }
    catch (InvalidCipherTextException e)
    {
        if (!"pad block corrupted".equals(e.getMessage()))
        {
            fail("wrong exception for corrupt padding: " + e);
        }
    } 

    testPadding(new ISO10126d2Padding(), rand,
                                null,
                                null);

    testPadding(new X923Padding(), rand,
                                null,
                                null);

    testPadding(new TBCPadding(), rand,
                                Hex.decode("ffffff0000000000"),
                                Hex.decode("00000000ffffffff"));

    testPadding(new ZeroBytePadding(), rand,
                                Hex.decode("ffffff0000000000"),
                                null);

    testPadding(new ISO7816d4Padding(), rand,
                                Hex.decode("ffffff8000000000"),
                                Hex.decode("0000000080000000"));

    testOutputSizes();

}
项目:Aki-SSL    文件:BaseBlockCipher.java   
protected void engineSetPadding(
    String  padding)
throws NoSuchPaddingException
{
    String  paddingName = Strings.toUpperCase(padding);

    if (paddingName.equals("NOPADDING"))
    {
        if (cipher.wrapOnNoPadding())
        {
            cipher = new BufferedGenericBlockCipher(new BufferedBlockCipher(cipher.getUnderlyingCipher()));
        }
    }
    else if (paddingName.equals("WITHCTS"))
    {
        cipher = new BufferedGenericBlockCipher(new CTSBlockCipher(cipher.getUnderlyingCipher()));
    }
    else
    {
        padded = true;

        if (isAEADModeName(modeName))
        {
            throw new NoSuchPaddingException("Only NoPadding can be used with AEAD modes.");
        }
        else if (paddingName.equals("PKCS5PADDING") || paddingName.equals("PKCS7PADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher());
        }
        else if (paddingName.equals("ZEROBYTEPADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new ZeroBytePadding());
        }
        else if (paddingName.equals("ISO10126PADDING") || paddingName.equals("ISO10126-2PADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new ISO10126d2Padding());
        }
        else if (paddingName.equals("X9.23PADDING") || paddingName.equals("X923PADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new X923Padding());
        }
        else if (paddingName.equals("ISO7816-4PADDING") || paddingName.equals("ISO9797-1PADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new ISO7816d4Padding());
        }
        else if (paddingName.equals("TBCPADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new TBCPadding());
        }
        else
        {
            throw new NoSuchPaddingException("Padding " + padding + " unknown.");
        }
    }
}
项目:CryptMeme    文件:BaseBlockCipher.java   
protected void engineSetPadding(
    String  padding)
throws NoSuchPaddingException
{
    String  paddingName = Strings.toUpperCase(padding);

    if (paddingName.equals("NOPADDING"))
    {
        if (cipher.wrapOnNoPadding())
        {
            cipher = new BufferedGenericBlockCipher(new BufferedBlockCipher(cipher.getUnderlyingCipher()));
        }
    }
    else if (paddingName.equals("WITHCTS"))
    {
        cipher = new BufferedGenericBlockCipher(new CTSBlockCipher(cipher.getUnderlyingCipher()));
    }
    else
    {
        padded = true;

        if (isAEADModeName(modeName))
        {
            throw new NoSuchPaddingException("Only NoPadding can be used with AEAD modes.");
        }
        else if (paddingName.equals("PKCS5PADDING") || paddingName.equals("PKCS7PADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher());
        }
        else if (paddingName.equals("ZEROBYTEPADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new ZeroBytePadding());
        }
        else if (paddingName.equals("ISO10126PADDING") || paddingName.equals("ISO10126-2PADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new ISO10126d2Padding());
        }
        else if (paddingName.equals("X9.23PADDING") || paddingName.equals("X923PADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new X923Padding());
        }
        else if (paddingName.equals("ISO7816-4PADDING") || paddingName.equals("ISO9797-1PADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new ISO7816d4Padding());
        }
        else if (paddingName.equals("TBCPADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new TBCPadding());
        }
        else
        {
            throw new NoSuchPaddingException("Padding " + padding + " unknown.");
        }
    }
}
项目:irma_future_id    文件:PaddingTest.java   
public void performTest()
{
    SecureRandom    rand = new SecureRandom(new byte[20]);

    rand.setSeed(System.currentTimeMillis());

    testPadding(new PKCS7Padding(), rand,
                                Hex.decode("ffffff0505050505"),
                                Hex.decode("0000000004040404"));

    PKCS7Padding padder = new PKCS7Padding();
    try
    {
        padder.padCount(new byte[8]);

        fail("invalid padding not detected");
    }
    catch (InvalidCipherTextException e)
    {
        if (!"pad block corrupted".equals(e.getMessage()))
        {
            fail("wrong exception for corrupt padding: " + e);
        }
    } 

    testPadding(new ISO10126d2Padding(), rand,
                                null,
                                null);

    testPadding(new X923Padding(), rand,
                                null,
                                null);

    testPadding(new TBCPadding(), rand,
                                Hex.decode("ffffff0000000000"),
                                Hex.decode("00000000ffffffff"));

    testPadding(new ZeroBytePadding(), rand,
                                Hex.decode("ffffff0000000000"),
                                null);

    testPadding(new ISO7816d4Padding(), rand,
                                Hex.decode("ffffff8000000000"),
                                Hex.decode("0000000080000000"));
}
项目:irma_future_id    文件:BaseBlockCipher.java   
protected void engineSetPadding(
    String  padding)
throws NoSuchPaddingException
{
    String  paddingName = Strings.toUpperCase(padding);

    if (paddingName.equals("NOPADDING"))
    {
        if (cipher.wrapOnNoPadding())
        {
            cipher = new BufferedGenericBlockCipher(new BufferedBlockCipher(cipher.getUnderlyingCipher()));
        }
    }
    else if (paddingName.equals("WITHCTS"))
    {
        cipher = new BufferedGenericBlockCipher(new CTSBlockCipher(cipher.getUnderlyingCipher()));
    }
    else
    {
        padded = true;

        if (isAEADModeName(modeName))
        {
            throw new NoSuchPaddingException("Only NoPadding can be used with AEAD modes.");
        }
        else if (paddingName.equals("PKCS5PADDING") || paddingName.equals("PKCS7PADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher());
        }
        else if (paddingName.equals("ZEROBYTEPADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new ZeroBytePadding());
        }
        else if (paddingName.equals("ISO10126PADDING") || paddingName.equals("ISO10126-2PADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new ISO10126d2Padding());
        }
        else if (paddingName.equals("X9.23PADDING") || paddingName.equals("X923PADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new X923Padding());
        }
        else if (paddingName.equals("ISO7816-4PADDING") || paddingName.equals("ISO9797-1PADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new ISO7816d4Padding());
        }
        else if (paddingName.equals("TBCPADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new TBCPadding());
        }
        else
        {
            throw new NoSuchPaddingException("Padding " + padding + " unknown.");
        }
    }
}
项目:bc-java    文件:PaddingTest.java   
public void performTest()
{
    SecureRandom    rand = new SecureRandom(new byte[20]);

    rand.setSeed(System.currentTimeMillis());

    testPadding(new PKCS7Padding(), rand,
                                Hex.decode("ffffff0505050505"),
                                Hex.decode("0000000004040404"));

    PKCS7Padding padder = new PKCS7Padding();
    try
    {
        padder.padCount(new byte[8]);

        fail("invalid padding not detected");
    }
    catch (InvalidCipherTextException e)
    {
        if (!"pad block corrupted".equals(e.getMessage()))
        {
            fail("wrong exception for corrupt padding: " + e);
        }
    } 

    testPadding(new ISO10126d2Padding(), rand,
                                null,
                                null);

    testPadding(new X923Padding(), rand,
                                null,
                                null);

    testPadding(new TBCPadding(), rand,
                                Hex.decode("ffffff0000000000"),
                                Hex.decode("00000000ffffffff"));

    testPadding(new ZeroBytePadding(), rand,
                                Hex.decode("ffffff0000000000"),
                                null);

    testPadding(new ISO7816d4Padding(), rand,
                                Hex.decode("ffffff8000000000"),
                                Hex.decode("0000000080000000"));
}
项目:bc-java    文件:BaseBlockCipher.java   
protected void engineSetPadding(
    String  padding)
throws NoSuchPaddingException
{
    String  paddingName = Strings.toUpperCase(padding);

    if (paddingName.equals("NOPADDING"))
    {
        if (cipher.wrapOnNoPadding())
        {
            cipher = new BufferedGenericBlockCipher(new BufferedBlockCipher(cipher.getUnderlyingCipher()));
        }
    }
    else if (paddingName.equals("WITHCTS"))
    {
        cipher = new BufferedGenericBlockCipher(new CTSBlockCipher(cipher.getUnderlyingCipher()));
    }
    else
    {
        padded = true;

        if (isAEADModeName(modeName))
        {
            throw new NoSuchPaddingException("Only NoPadding can be used with AEAD modes.");
        }
        else if (paddingName.equals("PKCS5PADDING") || paddingName.equals("PKCS7PADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher());
        }
        else if (paddingName.equals("ZEROBYTEPADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new ZeroBytePadding());
        }
        else if (paddingName.equals("ISO10126PADDING") || paddingName.equals("ISO10126-2PADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new ISO10126d2Padding());
        }
        else if (paddingName.equals("X9.23PADDING") || paddingName.equals("X923PADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new X923Padding());
        }
        else if (paddingName.equals("ISO7816-4PADDING") || paddingName.equals("ISO9797-1PADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new ISO7816d4Padding());
        }
        else if (paddingName.equals("TBCPADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new TBCPadding());
        }
        else
        {
            throw new NoSuchPaddingException("Padding " + padding + " unknown.");
        }
    }
}