Examples of Mac


Examples of javax.crypto.Mac

        PBEParameterSpec defParams = new PBEParameterSpec(salt, itCount);
        PBEKeySpec pbeSpec = new PBEKeySpec(password);
        BCPBEKey key = (BCPBEKey)keyFact.generateSecret(pbeSpec);
        key.setTryWrongPKCS12Zero(wrongPkcs12Zero);

        Mac mac = Mac.getInstance(oid.getId(), bcProvider);
        mac.init(key, defParams);
        mac.update(data);
        return mac.doFinal();
    }
View Full Code Here

Examples of javax.crypto.Mac

    }

    private void aliasTest(SecretKey key, String primary, String[] aliases)
        throws Exception
    {
        Mac mac = Mac.getInstance(primary, "BC");

        //
        // standard DAC - zero IV
        //
        mac.init(key);

        mac.update(input, 0, input.length);

        byte[] ref = mac.doFinal();

        for (int i = 0; i != aliases.length; i++)
        {
            mac = Mac.getInstance(aliases[i], "BC");

            mac.init(key);

            mac.update(input, 0, input.length);

            byte[] out = mac.doFinal();
            if (!areEqual(out, ref))
            {
                fail("Failed - expected " + new String(Hex.encode(ref)) + " got " + new String(Hex.encode(out)));
            }
        }
View Full Code Here

Examples of javax.crypto.Mac

    public void performTest()
        throws Exception
    {
        SecretKey           key = new SecretKeySpec(keyBytes, "DES");
        byte[]              out;
        Mac                 mac;

        mac = Mac.getInstance("DESMac", "BC");

        //
        // standard DAC - zero IV
        //
        mac.init(key);

        mac.update(input, 0, input.length);

        out = mac.doFinal();

        if (!areEqual(out, output1))
        {
            fail("Failed - expected " + new String(Hex.encode(output1)) + " got " + new String(Hex.encode(out)));
        }
       
        //
        // mac with IV.
        //
        mac.init(key, new IvParameterSpec(ivBytes));

        mac.update(input, 0, input.length);

        out = mac.doFinal();

        if (!areEqual(out, output2))
        {
            fail("Failed - expected " + new String(Hex.encode(output2)) + " got " + new String(Hex.encode(out)));
        }
       
        //
        // CFB mac with IV - 8 bit CFB mode
        //
        mac = Mac.getInstance("DESMac/CFB8", "BC");

        mac.init(key, new IvParameterSpec(ivBytes));

        mac.update(input, 0, input.length);

        out = mac.doFinal();

        if (!areEqual(out, output3))
        {
            fail("Failed - expected " + new String(Hex.encode(output3)) + " got " + new String(Hex.encode(out)));
        }
       
        //
        // ISO9797 algorithm 3 using DESEDE
        //
        key = new SecretKeySpec(keyBytesISO9797, "DESEDE");
       
        mac = Mac.getInstance("ISO9797ALG3", "BC");

        mac.init(key);

        mac.update(inputISO9797, 0, inputISO9797.length);

        out = mac.doFinal();

        if (!areEqual(out, outputISO9797))
        {
            fail("Failed - expected " + new String(Hex.encode(outputISO9797)) + " got " + new String(Hex.encode(out)));
        }
       
        //
        // 64bit DESede Mac
        //
        key = new SecretKeySpec(keyBytesISO9797, "DESEDE");
       
        mac = Mac.getInstance("DESEDE64", "BC");

        mac.init(key);

        mac.update(inputDesEDE64, 0, inputDesEDE64.length);

        out = mac.doFinal();

        if (!areEqual(out, outputDesEDE64))
        {
            fail("Failed - expected " + new String(Hex.encode(outputDesEDE64)) + " got " + new String(Hex.encode(out)));
        }
View Full Code Here

Examples of javax.crypto.Mac

        String  hmacName,
        byte[]  output)
    {
        SecretKey           key;
        byte[]              out;
        Mac                 mac;

        try
        {
            SecretKeyFactory    fact = SecretKeyFactory.getInstance(hmacName, "BC");

            key = fact.generateSecret(new PBEKeySpec("hello".toCharArray()));
           
            mac = Mac.getInstance(hmacName, "BC");
        }
        catch (Exception e)
        {
            fail("Failed - exception " + e.toString(), e);
            return;
        }

        try
        {
            mac.init(key, new PBEParameterSpec(new byte[20], 100));
        }
        catch (Exception e)
        {
            fail("Failed - exception " + e.toString(), e);
            return;
        }

        mac.reset();
       
        mac.update(message, 0, message.length);

        out = mac.doFinal();

        if (!Arrays.areEqual(out, output))
        {
            fail("Failed - expected " + new String(Hex.encode(output)) + " got " + new String(Hex.encode(out)));
        }
View Full Code Here

Examples of javax.crypto.Mac

        String  hmacName,
        byte[]  output)
    {
        SecretKey           key;
        byte[]              out;
        Mac                 mac;

        try
        {
            SecretKeyFactory    fact = SecretKeyFactory.getInstance(hmacName, "BC");

            key = fact.generateSecret(new PBEKeySpec("hello".toCharArray(), new byte[20], 100, 160));

            mac = Mac.getInstance("HMAC-SHA1", "BC");
        }
        catch (Exception e)
        {
            fail("Failed - exception " + e.toString(), e);
            return;
        }

        try
        {
            mac.init(key);
        }
        catch (Exception e)
        {
            fail("Failed - exception " + e.toString(), e);
            return;
        }

        mac.reset();

        mac.update(message, 0, message.length);

        out = mac.doFinal();

        if (!Arrays.areEqual(out, output))
        {
            fail("Failed - expected " + new String(Hex.encode(output)) + " got " + new String(Hex.encode(out)));
        }
View Full Code Here

Examples of javax.crypto.Mac

    private void checkMac(String name, List missingMacs, List missingKeyGens, String macOutput)
    {
        try
        {
            Mac mac = Mac.getInstance(name);

            mac.init(new SecretKeySpec(new byte[mac.getMacLength()], mac.getAlgorithm()), new IvParameterSpec(
                new byte[16]));
            mac.update(new byte[128]);
            byte[] bytes = mac.doFinal();

            if (!Arrays.areEqual(bytes, Hex.decode(macOutput)))
            {
                fail("wrong mac value computed for " + name);
            }
View Full Code Here

Examples of javax.crypto.Mac

       
        String auth;
        try {
            final SecretKeySpec signingKey = new SecretKeySpec(m_password.getBytes(), SIGNATURE_ALGORITHM);

            final Mac mac = Mac.getInstance(SIGNATURE_ALGORITHM);
            mac.init(signingKey);

            // BASE64Encoder isn't technically a public class, but it
            // has been consistently available in Java releases to date
            auth = Base64.encodeBytes(mac.doFinal(buf.toString().getBytes()));
        }
        catch(Exception e) {
            throw new IllegalArgumentException("Unable to calculate digest", e);
        }
View Full Code Here

Examples of javax.crypto.Mac

    {
        try
        {
            SecretKey sk = new SecretKeySpec( key, "AES" );

            Mac mac = Mac.getInstance( "HmacSHA1" );
            mac.init( sk );

            return mac.doFinal( data );
        }
        catch ( GeneralSecurityException nsae )
        {
            nsae.printStackTrace();
            return null;
View Full Code Here

Examples of javax.crypto.Mac

    {
        try
        {
            SecretKey sk = new SecretKeySpec( key, "DESede" );

            Mac mac = Mac.getInstance( "HmacSHA1" );
            mac.init( sk );

            return mac.doFinal( data );
        }
        catch ( GeneralSecurityException nsae )
        {
            nsae.printStackTrace();
            return null;
View Full Code Here

Examples of net.schmizz.sshj.transport.mac.MAC

                                                            negotiatedAlgs.getServer2ClientCipherAlgorithm());
        cipher_S2C.init(Cipher.Mode.Decrypt,
                        resizedKey(encryptionKey_S2C, cipher_S2C.getBlockSize(), hash, kex.getK(), kex.getH()),
                        initialIV_S2C);

        final MAC mac_C2S = Factory.Named.Util.create(transport.getConfig().getMACFactories(), negotiatedAlgs
                .getClient2ServerMACAlgorithm());
        mac_C2S.init(integrityKey_C2S);

        final MAC mac_S2C = Factory.Named.Util.create(transport.getConfig().getMACFactories(),
                                                      negotiatedAlgs.getServer2ClientMACAlgorithm());
        mac_S2C.init(integrityKey_S2C);

        final Compression compression_S2C =
                Factory.Named.Util.create(transport.getConfig().getCompressionFactories(),
                                          negotiatedAlgs.getServer2ClientCompressionAlgorithm());
        final Compression compression_C2S =
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.