當前位置: 首頁>>代碼示例>>Java>>正文


Java Arrays類代碼示例

本文整理匯總了Java中org.bouncycastle.util.Arrays的典型用法代碼示例。如果您正苦於以下問題:Java Arrays類的具體用法?Java Arrays怎麽用?Java Arrays使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Arrays類屬於org.bouncycastle.util包,在下文中一共展示了Arrays類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: verifyUserSig

import org.bouncycastle.util.Arrays; //導入依賴的package包/類
@Override
public boolean verifyUserSig(String identifier, String sig)throws QCloudException {
    try {
        Security.addProvider(new BouncyCastleProvider());
        
        //DeBaseUrl64 urlSig to json
        Base64 decoder = new Base64();

        byte [] compressBytes = Base64Url.base64DecodeUrl(sig.getBytes(Charset.forName("UTF-8")));
        
        //Decompression
        Inflater decompression =  new Inflater();
        decompression.setInput(compressBytes, 0, compressBytes.length);
        byte [] decompressBytes = new byte [1024];
        int decompressLength = decompression.inflate(decompressBytes);
        decompression.end();
        
        String jsonString = new String(Arrays.copyOfRange(decompressBytes, 0, decompressLength));
        
        //Get TLS.Sig from json
        JSONObject jsonObject= JSON.parseObject(jsonString);
        String sigTLS = jsonObject.getString("TLS.sig");
        
        //debase64 TLS.Sig to get serailString
        byte[] signatureBytes = decoder.decode(sigTLS.getBytes(Charset.forName("UTF-8")));
        
        String strSdkAppid = jsonObject.getString("TLS.sdk_appid");
        String sigTime = jsonObject.getString("TLS.time");
        String sigExpire = jsonObject.getString("TLS.expire_after");
        
        if (!imConfig.getSdkAppId().equals(strSdkAppid))
        {
            return false;
        }

        if ( System.currentTimeMillis()/1000 - Long.parseLong(sigTime) > Long.parseLong(sigExpire)) {
            return false;
        }
        
        //Get Serial String from json
        String SerialString = 
            "TLS.appid_at_3rd:" + 0 + "\n" +
            "TLS.account_type:" + 0 + "\n" +
            "TLS.identifier:" + identifier + "\n" + 
            "TLS.sdk_appid:" + imConfig.getSdkAppId() + "\n" + 
            "TLS.time:" + sigTime + "\n" + 
            "TLS.expire_after:" + sigExpire + "\n";
    
        Reader reader = new CharArrayReader(imConfig.getPublicKey().toCharArray());
        PEMParser  parser = new PEMParser(reader);
        JcaPEMKeyConverter converter = new JcaPEMKeyConverter();
        Object obj = parser.readObject();
        parser.close();
        PublicKey pubKeyStruct  = converter.getPublicKey((SubjectPublicKeyInfo) obj);

        Signature signature = Signature.getInstance("SHA256withECDSA","BC");
        signature.initVerify(pubKeyStruct);
        signature.update(SerialString.getBytes(Charset.forName("UTF-8")));
        return signature.verify(signatureBytes);
    }catch (Exception e) {
        throw new QCloudException(e);
    }
}
 
開發者ID:51wakeup,項目名稱:wakeup-qcloud-sdk,代碼行數:64,代碼來源:DefaultQCloudClient.java

示例2: processFinishedMessage

import org.bouncycastle.util.Arrays; //導入依賴的package包/類
protected void processFinishedMessage(ByteArrayInputStream buf)
    throws IOException
{

    byte[] verify_data = TlsUtils.readFully(expected_verify_data.length, buf);

    assertEmpty(buf);

    /*
     * Compare both checksums.
     */
    if (!Arrays.constantTimeAreEqual(expected_verify_data, verify_data))
    {
        /*
         * Wrong checksum in the finished message.
         */
        this.failWithError(AlertLevel.fatal, AlertDescription.decrypt_error);
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:20,代碼來源:TlsProtocol.java

示例3: asn1Equals

import org.bouncycastle.util.Arrays; //導入依賴的package包/類
boolean asn1Equals(
    DERObject  o)
{
    if (!(o instanceof DEREnumerated))
    {
        return false;
    }

    DEREnumerated other = (DEREnumerated)o;

    return Arrays.areEqual(this.bytes, other.bytes);
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:13,代碼來源:DEREnumerated.java

示例4: hashCode

import org.bouncycastle.util.Arrays; //導入依賴的package包/類
public int hashCode()
{
    int code = Arrays.hashCode(subjectKeyId);

    if (this.serialNumber != null)
    {
        code ^= this.serialNumber.hashCode();
    }

    if (this.issuer != null)
    {
        code ^= this.issuer.hashCode();
    }

    return code;
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:17,代碼來源:X509CertificateHolderSelector.java

示例5: equals

import org.bouncycastle.util.Arrays; //導入依賴的package包/類
public boolean equals(
    Object  o)
{
    if (!(o instanceof X509CertificateHolderSelector))
    {
        return false;
    }

    X509CertificateHolderSelector id = (X509CertificateHolderSelector)o;

    return Arrays.areEqual(subjectKeyId, id.subjectKeyId)
        && equalsObj(this.serialNumber, id.serialNumber)
        && equalsObj(this.issuer, id.issuer);
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:15,代碼來源:X509CertificateHolderSelector.java

示例6: exponentiateX

import org.bouncycastle.util.Arrays; //導入依賴的package包/類
public void exponentiateX(long pow, byte[] output)
{
    // Initial value is little-endian 1
    byte[] y = GCMUtil.oneAsBytes();

    if (pow > 0)
    {
        byte[] powX = Arrays.clone(x);
        do
        {
            if ((pow & 1L) != 0)
            {
                GCMUtil.multiply(y, powX);
            }
            GCMUtil.multiply(powX, powX);
            pow >>>= 1;
        }
        while (pow > 0);
    }

    System.arraycopy(y, 0, output, 0, 16);
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:23,代碼來源:BasicGCMExponentiator.java

示例7: isValid

import org.bouncycastle.util.Arrays; //導入依賴的package包/類
public boolean isValid(PKMACValue value, char[] password, SubjectPublicKeyInfo keyInfo)
    throws CRMFException
{
    builder.setParameters(PBMParameter.getInstance(value.getAlgId().getParameters()));
    MacCalculator calculator = builder.build(password);

    OutputStream macOut = calculator.getOutputStream();

    try
    {
        macOut.write(keyInfo.getEncoded(ASN1Encoding.DER));

        macOut.close();
    }
    catch (IOException e)
    {
        throw new CRMFException("exception encoding mac input: " + e.getMessage(), e);
    }

    return Arrays.areEqual(calculator.getMac(), value.getValue().getBytes());
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:22,代碼來源:PKMACValueVerifier.java

示例8: unionIPRange

import org.bouncycastle.util.Arrays; //導入依賴的package包/類
/**
 * Calculates the union if two IP ranges.
 *
 * @param ipWithSubmask1 The first IP address with its subnet mask.
 * @param ipWithSubmask2 The second IP address with its subnet mask.
 * @return A <code>Set</code> with the union of both addresses.
 */
private Set unionIPRange(byte[] ipWithSubmask1, byte[] ipWithSubmask2)
{
    Set set = new HashSet();

    // difficult, adding always all IPs is not wrong
    if (Arrays.areEqual(ipWithSubmask1, ipWithSubmask2))
    {
        set.add(ipWithSubmask1);
    }
    else
    {
        set.add(ipWithSubmask1);
        set.add(ipWithSubmask2);
    }
    return set;
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:24,代碼來源:PKIXNameConstraintValidator.java

示例9: isIPConstrained

import org.bouncycastle.util.Arrays; //導入依賴的package包/類
/**
 * Checks if the IP address <code>ip</code> is constrained by
 * <code>constraint</code>.
 *
 * @param ip         The IP address.
 * @param constraint The constraint. This is an IP address concatenated with
 *                   its subnetmask.
 * @return <code>true</code> if constrained, <code>false</code>
 *         otherwise.
 */
private boolean isIPConstrained(byte ip[], byte[] constraint)
{
    int ipLength = ip.length;

    if (ipLength != (constraint.length / 2))
    {
        return false;
    }

    byte[] subnetMask = new byte[ipLength];
    System.arraycopy(constraint, ipLength, subnetMask, 0, ipLength);

    byte[] permittedSubnetAddress = new byte[ipLength];

    byte[] ipSubnetAddress = new byte[ipLength];

    // the resulting IP address by applying the subnet mask
    for (int i = 0; i < ipLength; i++)
    {
        permittedSubnetAddress[i] = (byte)(constraint[i] & subnetMask[i]);
        ipSubnetAddress[i] = (byte)(ip[i] & subnetMask[i]);
    }

    return Arrays.areEqual(permittedSubnetAddress, ipSubnetAddress);
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:36,代碼來源:PKIXNameConstraintValidator.java

示例10: reset

import org.bouncycastle.util.Arrays; //導入依賴的package包/類
private void reset(
    boolean clearMac)
{
    cipher.reset(); // TODO Redundant since the mac will reset it?
    mac.reset();

    bufOff = 0;
    Arrays.fill(bufBlock, (byte)0);

    if (clearMac)
    {
        Arrays.fill(macBlock, (byte)0);
    }

    byte[] tag = new byte[blockSize];
    tag[blockSize - 1] = hTAG;
    mac.update(tag, 0, blockSize);

    cipherInitialized = false;

    if (initialAssociatedText != null)
    {
       processAADBytes(initialAssociatedText, 0, initialAssociatedText.length);
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:26,代碼來源:EAXBlockCipher.java

示例11: engineInit

import org.bouncycastle.util.Arrays; //導入依賴的package包/類
protected void engineInit(
    byte[] params)
    throws IOException
{
    //
    // check that we don't have a DER encoded octet string
    //
    if ((params.length % 8) != 0
        && params[0] == 0x04 && params[1] == params.length - 2)
    {
        ASN1OctetString oct = (ASN1OctetString)ASN1Primitive.fromByteArray(params);

        params = oct.getOctets();
    }

    this.iv = Arrays.clone(params);
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:18,代碼來源:IvAlgorithmParameters.java

示例12: equals

import org.bouncycastle.util.Arrays; //導入依賴的package包/類
private boolean equals(Object o1, Object o2)
{
    if (o1 == o2)
    {
        return true;
    }
    if (o1 == null || o2 == null)
    {
        return false;
    }
    if (o1 instanceof byte[] && o2 instanceof byte[])
    {
        return Arrays.areEqual((byte[])o1, (byte[])o2);
    }
    else
    {
        return o1.equals(o2);
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:20,代碼來源:PKIXNameConstraintValidator.java

示例13: isMacValid

import org.bouncycastle.util.Arrays; //導入依賴的package包/類
/**
 * Verify the MacData attached to the PFX is consistent with what is expected.
 *
 * @param macCalcProviderBuilder provider builder for the calculator for the MAC
 * @param password password to use
 * @return true if mac data is valid, false otherwise.
 * @throws PKCSException if there is a problem evaluating the MAC.
 * @throws IllegalStateException if no MAC is actually present
 */
public boolean isMacValid(PKCS12MacCalculatorBuilderProvider macCalcProviderBuilder, char[] password)
    throws PKCSException
{
    if (hasMac())
    {
        MacData pfxmData = pfx.getMacData();
        MacDataGenerator mdGen = new MacDataGenerator(macCalcProviderBuilder.get(new AlgorithmIdentifier(pfxmData.getMac().getAlgorithmId().getAlgorithm(), new PKCS12PBEParams(pfxmData.getSalt(), pfxmData.getIterationCount().intValue()))));

        try
        {
            MacData mData = mdGen.build(
                password,
                ASN1OctetString.getInstance(pfx.getAuthSafe().getContent()).getOctets());

            return Arrays.constantTimeAreEqual(mData.getEncoded(), pfx.getMacData().getEncoded());
        }
        catch (IOException e)
        {
            throw new PKCSException("unable to process AuthSafe: " + e.getMessage());
        }
    }

    throw new IllegalStateException("no MAC present on PFX");
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:34,代碼來源:PKCS12PfxPdu.java

示例14: equals

import org.bouncycastle.util.Arrays; //導入依賴的package包/類
public boolean equals(Object obj)
{
    if (this == obj)
    {
        return true;
    }
    if (obj == null)
    {
        return false;
    }
    if (getClass() != obj.getClass())
    {
        return false;
    }
    BigIntPolynomial other = (BigIntPolynomial)obj;
    if (!Arrays.areEqual(coeffs, other.coeffs))
    {
        return false;
    }
    return true;
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:22,代碼來源:BigIntPolynomial.java

示例15: reset

import org.bouncycastle.util.Arrays; //導入依賴的package包/類
public void reset()
{

    v0 = k0 ^ 0x736f6d6570736575L;
    v1 = k1 ^ 0x646f72616e646f6dL;
    v2 = k0 ^ 0x6c7967656e657261L;
    v3 = k1 ^ 0x7465646279746573L;

    Arrays.fill(buf, (byte)0);
    bufPos = 0;
    wordCount = 0;
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:13,代碼來源:SipHash.java


注:本文中的org.bouncycastle.util.Arrays類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。