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


Java JCAUtil类代码示例

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


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

示例1: engineUpdate

import sun.security.jca.JCAUtil; //导入依赖的package包/类
/**
 * Update the digest using the specified ByteBuffer. The digest is
 * updated using the {@code input.remaining()} bytes starting
 * at {@code input.position()}.
 * Upon return, the buffer's position will be equal to its limit;
 * its limit will not have changed.
 *
 * @param input the ByteBuffer
 * @since 1.5
 */
protected void engineUpdate(ByteBuffer input) {
    if (input.hasRemaining() == false) {
        return;
    }
    if (input.hasArray()) {
        byte[] b = input.array();
        int ofs = input.arrayOffset();
        int pos = input.position();
        int lim = input.limit();
        engineUpdate(b, ofs + pos, lim - pos);
        input.position(lim);
    } else {
        int len = input.remaining();
        int n = JCAUtil.getTempArraySize(len);
        if ((tempArray == null) || (n > tempArray.length)) {
            tempArray = new byte[n];
        }
        while (len > 0) {
            int chunk = Math.min(len, tempArray.length);
            input.get(tempArray, 0, chunk);
            engineUpdate(tempArray, 0, chunk);
            len -= chunk;
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:36,代码来源:MessageDigestSpi.java

示例2: engineSign

import sun.security.jca.JCAUtil; //导入依赖的package包/类
@Override
protected byte[] engineSign() throws SignatureException {
    byte[] s = privateKey.getS().toByteArray();
    ECParameterSpec params = privateKey.getParams();
    // DER OID
    byte[] encodedParams = ECUtil.encodeECParameterSpec(null, params);
    int keySize = params.getCurve().getField().getFieldSize();

    // seed is twice the key size (in bytes) plus 1
    byte[] seed = new byte[(((keySize + 7) >> 3) + 1) * 2];
    if (random == null) {
        random = JCAUtil.getSecureRandom();
    }
    random.nextBytes(seed);

    try {

        return encodeSignature(
            signDigest(getDigestValue(), s, encodedParams, seed));

    } catch (GeneralSecurityException e) {
        throw new SignatureException("Could not sign data", e);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:ECDSASignature.java

示例3: generateKeyPair

import sun.security.jca.JCAUtil; //导入依赖的package包/类
/**
 * Generates a pair of keys usable by any JavaSecurity compliant
 * DSA implementation.
 */
public KeyPair generateKeyPair() {
    if (random == null) {
        random = JCAUtil.getSecureRandom();
    }
    DSAParameterSpec spec;
    try {
        if (forceNewParameters) {
            // generate new parameters each time
            spec = ParameterCache.getNewDSAParameterSpec(plen, qlen, random);
        } else {
            if (params == null) {
                params =
                    ParameterCache.getDSAParameterSpec(plen, qlen, random);
            }
            spec = params;
        }
    } catch (GeneralSecurityException e) {
        throw new ProviderException(e);
    }
    return generateKeyPair(spec.getP(), spec.getQ(), spec.getG(), random);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:DSAKeyPairGenerator.java

示例4: engineUpdate

import sun.security.jca.JCAUtil; //导入依赖的package包/类
/**
    * Update the digest using the specified ByteBuffer. The digest is
    * updated using the <code>input.remaining()</code> bytes starting
    * at <code>input.position()</code>.
    * Upon return, the buffer's position will be equal to its limit;
    * its limit will not have changed.
    *
    * @param input the ByteBuffer
    * @since 1.5
    */
   protected void engineUpdate(ByteBuffer input) {
if (input.hasRemaining() == false) {
    return;
}
if (input.hasArray()) {
    byte[] b = input.array();
    int ofs = input.arrayOffset();
    int pos = input.position();
    int lim = input.limit();
    engineUpdate(b, ofs + pos, lim - pos);
    input.position(lim);
} else {
    int len = input.remaining();
    int n = JCAUtil.getTempArraySize(len);
    if ((tempArray == null) || (n > tempArray.length)) {
	tempArray = new byte[n];
    }
    while (len > 0) {
	int chunk = Math.min(len, tempArray.length);
	input.get(tempArray, 0, chunk);
	engineUpdate(tempArray, 0, chunk);
	len -= chunk;
    }
}
   }
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:36,代码来源:MessageDigestSpi.java

示例5: engineUpdate

import sun.security.jca.JCAUtil; //导入依赖的package包/类
/**
 * Update the digest using the specified ByteBuffer. The digest is
 * updated using the <code>input.remaining()</code> bytes starting
 * at <code>input.position()</code>.
 * Upon return, the buffer's position will be equal to its limit;
 * its limit will not have changed.
 *
 * @param input the ByteBuffer
 * @since 1.5
 */
protected void engineUpdate(ByteBuffer input) {
    if (input.hasRemaining() == false) {
        return;
    }
    if (input.hasArray()) {
        byte[] b = input.array();
        int ofs = input.arrayOffset();
        int pos = input.position();
        int lim = input.limit();
        engineUpdate(b, ofs + pos, lim - pos);
        input.position(lim);
    } else {
        int len = input.remaining();
        int n = JCAUtil.getTempArraySize(len);
        if ((tempArray == null) || (n > tempArray.length)) {
            tempArray = new byte[n];
        }
        while (len > 0) {
            int chunk = Math.min(len, tempArray.length);
            input.get(tempArray, 0, chunk);
            engineUpdate(tempArray, 0, chunk);
            len -= chunk;
        }
    }
}
 
开发者ID:ZhaoX,项目名称:jdk-1.7-annotated,代码行数:36,代码来源:MessageDigestSpi.java

示例6: engineSign

import sun.security.jca.JCAUtil; //导入依赖的package包/类
@Override
protected byte[] engineSign() throws SignatureException {
    byte[] s = privateKey.getS().toByteArray();
    ECParameterSpec params = privateKey.getParams();
    byte[] encodedParams = ECParameters.encodeParameters(params); // DER OID
    int keySize = params.getCurve().getField().getFieldSize();

    // seed is twice the key size (in bytes) plus 1
    byte[] seed = new byte[(((keySize + 7) >> 3) + 1) * 2];
    if (random == null) {
        random = JCAUtil.getSecureRandom();
    }
    random.nextBytes(seed);

    try {

        return encodeSignature(
            signDigest(getDigestValue(), s, encodedParams, seed));

    } catch (GeneralSecurityException e) {
        throw new SignatureException("Could not sign data", e);
    }
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:24,代码来源:ECDSASignature.java

示例7: generateKeyPair

import sun.security.jca.JCAUtil; //导入依赖的package包/类
/**
 * Generates a pair of keys usable by any JavaSecurity compliant
 * DSA implementation.
 */
public KeyPair generateKeyPair() {
    if (random == null) {
        random = JCAUtil.getSecureRandom();
    }
    DSAParameterSpec spec;
    try {
        if (forceNewParameters) {
            // generate new parameters each time
            spec = ParameterCache.getNewDSAParameterSpec(modlen, random);
        } else {
            if (params == null) {
                params =
                    ParameterCache.getDSAParameterSpec(modlen, random);
            }
            spec = params;
        }
    } catch (GeneralSecurityException e) {
        throw new ProviderException(e);
    }
    return generateKeyPair(spec.getP(), spec.getQ(), spec.getG(), random);
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:26,代码来源:DSAKeyPairGenerator.java

示例8: padV15

import sun.security.jca.JCAUtil; //导入依赖的package包/类
/**
 * PKCS#1 v1.5 padding (blocktype 1 and 2).
 */
private byte[] padV15(byte[] data) throws BadPaddingException {
    byte[] padded = new byte[paddedSize];
    System.arraycopy(data, 0, padded, paddedSize - data.length,
        data.length);
    int psSize = paddedSize - 3 - data.length;
    int k = 0;
    padded[k++] = 0;
    padded[k++] = (byte)type;
    if (type == PAD_BLOCKTYPE_1) {
        // blocktype 1: all padding bytes are 0xff
        while (psSize-- > 0) {
            padded[k++] = (byte)0xff;
        }
    } else {
        // blocktype 2: padding bytes are random non-zero bytes
        if (random == null) {
            random = JCAUtil.getSecureRandom();
        }
        // generate non-zero padding bytes
        // use a buffer to reduce calls to SecureRandom
        byte[] r = new byte[64];
        int i = -1;
        while (psSize-- > 0) {
            int b;
            do {
                if (i < 0) {
                    random.nextBytes(r);
                    i = r.length - 1;
                }
                b = r[i--] & 0xff;
            } while (b == 0);
            padded[k++] = (byte)b;
        }
    }
    return padded;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:40,代码来源:RSAPadding.java

示例9: generateKeyPair

import sun.security.jca.JCAUtil; //导入依赖的package包/类
@Override
public KeyPair generateKeyPair() {

    byte[] encodedParams =
        ECUtil.encodeECParameterSpec(null, (ECParameterSpec)params);

    // seed is twice the key size (in bytes) plus 1
    byte[] seed = new byte[(((keySize + 7) >> 3) + 1) * 2];
    if (random == null) {
        random = JCAUtil.getSecureRandom();
    }
    random.nextBytes(seed);

    try {

        Object[] keyBytes = generateECKeyPair(keySize, encodedParams, seed);

        // The 'params' object supplied above is equivalent to the native
        // one so there is no need to fetch it.
        // keyBytes[0] is the encoding of the native private key
        BigInteger s = new BigInteger(1, (byte[])keyBytes[0]);

        PrivateKey privateKey =
            new ECPrivateKeyImpl(s, (ECParameterSpec)params);

        // keyBytes[1] is the encoding of the native public key
        ECPoint w = ECUtil.decodePoint((byte[])keyBytes[1],
            ((ECParameterSpec)params).getCurve());
        PublicKey publicKey =
            new ECPublicKeyImpl(w, (ECParameterSpec)params);

        return new KeyPair(publicKey, privateKey);

    } catch (Exception e) {
        throw new ProviderException(e);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:38,代码来源:ECKeyPairGenerator.java


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