当前位置: 首页>>代码示例>>Java>>正文


Java BitArray类代码示例

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


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

示例1: DSAPublicKey

import sun.security.util.BitArray; //导入依赖的package包/类
/**
 * Make a DSA public key out of a public key and three parameters.
 * The p, q, and g parameters may be null, but if so, parameters will need
 * to be supplied from some other source before this key can be used in
 * cryptographic operations.  PKIX RFC2459bis explicitly allows DSA public
 * keys without parameters, where the parameters are provided in the
 * issuer's DSA public key.
 *
 * @param y the actual key bits
 * @param p DSA parameter p, may be null if all of p, q, and g are null.
 * @param q DSA parameter q, may be null if all of p, q, and g are null.
 * @param g DSA parameter g, may be null if all of p, q, and g are null.
 */
public DSAPublicKey(BigInteger y, BigInteger p, BigInteger q,
                    BigInteger g)
throws InvalidKeyException {
    this.y = y;
    algid = new AlgIdDSA(p, q, g);

    try {
        byte[] keyArray = new DerValue(DerValue.tag_Integer,
                           y.toByteArray()).toByteArray();
        setKey(new BitArray(keyArray.length*8, keyArray));
        encode();
    } catch (IOException e) {
        throw new InvalidKeyException("could not DER encode y: " +
                                      e.getMessage());
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:DSAPublicKey.java

示例2: setZero

import sun.security.util.BitArray; //导入依赖的package包/类
@Override
public void setZero(int[][] matrix) {
    final BitArray rows = new BitArray(matrix.length);
    final BitArray cols = new BitArray(matrix[0].length);
    for (int i = 0; i < matrix.length; i++) {
        for (int j = 0; j < matrix[i].length; j++) {
            final int item = matrix[i][j];
            rows.set(i, rows.get(i) || item == 0);
            cols.set(j, cols.get(j) || item == 0);
        }
    }
    for (int i = 0; i < rows.length(); i++) {
        for (int j = 0; j < cols.length(); j++) {
            if (rows.get(i) || cols.get(j)) {
                matrix[i][j] = 0;
            }
        }
    }
}
 
开发者ID:mmnaseri,项目名称:cs-review,代码行数:20,代码来源:ZeroMatrixImpl.java

示例3: parseIPv6

import sun.security.util.BitArray; //导入依赖的package包/类
private void parseIPv6(String name) throws IOException {

        int slashNdx = name.indexOf('/');
        if (slashNdx == -1) {
            address = InetAddress.getByName(name).getAddress();
        } else {
            address = new byte[32];
            byte[] base = InetAddress.getByName
                (name.substring(0, slashNdx)).getAddress();
            System.arraycopy(base, 0, address, 0, 16);

            // append a mask corresponding to the num of prefix bits specified
            int prefixLen = Integer.parseInt(name.substring(slashNdx+1));
            if (prefixLen > 128)
                throw new IOException("IPv6Address prefix is longer than 128");

            // create new bit array initialized to zeros
            BitArray bitArray = new BitArray(MASKSIZE * 8);

            // set all most significant bits up to prefix length
            for (int i = 0; i < prefixLen; i++)
                bitArray.set(i, true);
            byte[] maskArray = bitArray.toByteArray();

            // copy mask bytes into mask portion of address
            for (int i = 0; i < MASKSIZE; i++)
                address[MASKSIZE+i] = maskArray[i];
        }
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:IPAddressName.java

示例4: parseIPv6

import sun.security.util.BitArray; //导入依赖的package包/类
private void parseIPv6(String name) throws IOException {

        int slashNdx = name.indexOf('/');
        if (slashNdx == -1) {
            address = InetAddress.getByName(name).getAddress();
        } else {
            address = new byte[32];
            byte[] base = InetAddress.getByName
                (name.substring(0, slashNdx)).getAddress();
            System.arraycopy(base, 0, address, 0, 16);

            // append a mask corresponding to the num of prefix bits specified
            int prefixLen = Integer.parseInt(name.substring(slashNdx+1));
            if (prefixLen < 0 || prefixLen > 128) {
                throw new IOException("IPv6Address prefix length (" +
                        prefixLen + ") in out of valid range [0,128]");
            }

            // create new bit array initialized to zeros
            BitArray bitArray = new BitArray(MASKSIZE * 8);

            // set all most significant bits up to prefix length
            for (int i = 0; i < prefixLen; i++)
                bitArray.set(i, true);
            byte[] maskArray = bitArray.toByteArray();

            // copy mask bytes into mask portion of address
            for (int i = 0; i < MASKSIZE; i++)
                address[MASKSIZE+i] = maskArray[i];
        }
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:32,代码来源:IPAddressName.java

示例5: MyBitArray

import sun.security.util.BitArray; //导入依赖的package包/类
public MyBitArray(long length) {
  int arraySize = (int) (length / INTMAXLONG) + 1;
  bitArrays = new BitArray[arraySize];
  for (int i = 0; i < arraySize; i++) {
    bitArrays[i] = new BitArray(INTMAX);
  }
}
 
开发者ID:gigony,项目名称:GUITester-core,代码行数:8,代码来源:MyBitArray.java

示例6: KerberosFlags

import sun.security.util.BitArray; //导入依赖的package包/类
public KerberosFlags(int length) throws IllegalArgumentException {
    bits = new BitArray(length);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:4,代码来源:KerberosFlags.java

示例7: go

import sun.security.util.BitArray; //导入依赖的package包/类
void go() throws Exception {
    Context c = Context.fromJAAS("client");
    c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_SPNEGO_MECH_OID);

    byte[] token = c.doAs(new Action() {
        @Override
        public byte[] run(Context me, byte[] input) throws Exception {
            me.x().requestCredDeleg(true);
            me.x().requestReplayDet(false);
            me.x().requestSequenceDet(false);
            return me.x().initSecContext(new byte[0], 0, 0);
        }
    }, null);

    DerValue d = new DerValue(token);   // GSSToken
    DerInputStream ins = d.data;        // OID + mech token
    d.data.getDerValue();               // skip OID
    d = d.data.getDerValue();           // NegTokenInit
    d = d.data.getDerValue();           // The SEQUENCE inside

    boolean found = false;

    // Go through all fields inside NegTokenInit. The reqFlags field
    // is optional. It's even not recommended in RFC 4178.
    while (d.data.available() > 0) {
        DerValue d2 = d.data.getDerValue();
        if (d2.isContextSpecific((byte)1)) {
            found = true;
            System.out.println("regFlags field located.");
            BitArray ba = d2.data.getUnalignedBitString();
            if (ba.length() != 7) {
                throw new Exception("reqFlags should contain 7 bits");
            }
            if (!ba.get(0)) {
                throw new Exception("delegFlag should be true");
            }
            if (ba.get(2) || ba.get(3)) {
                throw new Exception("replay/sequenceFlag should be false");
            }
        }
    }

    if (!found) {
        System.out.println("Warning: regFlags field not found, too new?");
    }
    c.dispose();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:48,代码来源:SpnegoReqFlags.java

示例8: main

import sun.security.util.BitArray; //导入依赖的package包/类
public static void main(String[] argv) throws Exception {

        // Generates a NegTokenInit mechTypes field, with an
        // unsupported mech as the preferred.
        DerOutputStream mech = new DerOutputStream();
        mech.write(new Oid("1.2.3.4").getDER());
        mech.write(GSSUtil.GSS_KRB5_MECH_OID.getDER());
        DerOutputStream mechTypeList = new DerOutputStream();
        mechTypeList.write(DerValue.tag_Sequence, mech);

        // Generates a NegTokenInit mechToken field for 1.2.3.4 mech
        GSSHeader h1 = new GSSHeader(new ObjectIdentifier("1.2.3.4"), 1);
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        h1.encode(bout);
        bout.write(new byte[1]);

        // Generates the NegTokenInit token
        Constructor<NegTokenInit> ctor = NegTokenInit.class.getDeclaredConstructor(
                byte[].class, BitArray.class, byte[].class, byte[].class);
        ctor.setAccessible(true);
        NegTokenInit initToken = ctor.newInstance(
                mechTypeList.toByteArray(),
                new BitArray(0),
                bout.toByteArray(),
                null);
        Method m = Class.forName("sun.security.jgss.spnego.SpNegoToken")
                .getDeclaredMethod("getEncoded");
        m.setAccessible(true);
        byte[] spnegoToken = (byte[])m.invoke(initToken);

        // and wraps it into a GSSToken
        GSSHeader h = new GSSHeader(
                new ObjectIdentifier(GSSUtil.GSS_SPNEGO_MECH_OID.toString()),
                spnegoToken.length);
        bout = new ByteArrayOutputStream();
        h.encode(bout);
        bout.write(spnegoToken);
        byte[] token = bout.toByteArray();

        // and feeds it to a GSS acceptor
        GSSManager man = GSSManager.getInstance();
        GSSContext ctxt = man.createContext((GSSCredential) null);
        token = ctxt.acceptSecContext(token, 0, token.length);
        NegTokenTarg targ = new NegTokenTarg(token);

        // Make sure it's a GO-ON message
        Method m2 = NegTokenTarg.class.getDeclaredMethod("getNegotiatedResult");
        m2.setAccessible(true);
        int negResult = (int)m2.invoke(targ);

        if (negResult != 1 /* ACCEPT_INCOMPLETE */) {
            throw new Exception("Not a continue");
        }
    }
 
开发者ID:campolake,项目名称:openjdk9,代码行数:55,代码来源:NotPreferredMech.java


注:本文中的sun.security.util.BitArray类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。