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


Java DESedeKeySpec.isParityAdjusted方法代碼示例

本文整理匯總了Java中javax.crypto.spec.DESedeKeySpec.isParityAdjusted方法的典型用法代碼示例。如果您正苦於以下問題:Java DESedeKeySpec.isParityAdjusted方法的具體用法?Java DESedeKeySpec.isParityAdjusted怎麽用?Java DESedeKeySpec.isParityAdjusted使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.crypto.spec.DESedeKeySpec的用法示例。


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

示例1: engineGenerateSecret

import javax.crypto.spec.DESedeKeySpec; //導入方法依賴的package包/類
@Override
protected SecretKey engineGenerateSecret(KeySpec keySpec) throws InvalidKeySpecException {
    if (keySpec == null) {
        throw new InvalidKeySpecException("Null KeySpec");
    }
    if (keySpec instanceof SecretKeySpec) {
        SecretKeySpec key = (SecretKeySpec) keySpec;
        try {
            if (!DESedeKeySpec.isParityAdjusted(key.getEncoded(), 0)) {
                throw new InvalidKeySpecException(
                        "SecretKeySpec is not a parity-adjusted DESEDE key");
            }
        } catch (InvalidKeyException e) {
            throw new InvalidKeySpecException(e);
        }
        return key;
    } else if (keySpec instanceof DESedeKeySpec) {
        DESedeKeySpec desKeySpec = (DESedeKeySpec) keySpec;
        return new SecretKeySpec(desKeySpec.getKey(), "DESEDE");
    } else {
        throw new InvalidKeySpecException(
                "Unsupported KeySpec class: " + keySpec.getClass().getName());
    }
}
 
開發者ID:google,項目名稱:conscrypt,代碼行數:25,代碼來源:DESEDESecretKeyFactory.java

示例2: EncryptionKey

import javax.crypto.spec.DESedeKeySpec; //導入方法依賴的package包/類
/**
 * Generates a sub-sessionkey from a given session key.
 *
 * Used in AcceptSecContextToken and KrbApReq by acceptor- and initiator-
 * side respectively.
 */
public EncryptionKey(EncryptionKey key) throws KrbCryptoException {
    // generate random sub-session key
    keyValue = Confounder.bytes(key.keyValue.length);
    for (int i = 0; i < keyValue.length; i++) {
      keyValue[i] ^= key.keyValue[i];
    }
    keyType = key.keyType;

    // check for key parity and weak keys
    try {
        // check for DES key
        if ((keyType == EncryptedData.ETYPE_DES_CBC_MD5) ||
            (keyType == EncryptedData.ETYPE_DES_CBC_CRC)) {
            // fix DES key parity
            if (!DESKeySpec.isParityAdjusted(keyValue, 0)) {
                keyValue = Des.set_parity(keyValue);
            }
            // check for weak key
            if (DESKeySpec.isWeak(keyValue, 0)) {
                keyValue[7] = (byte)(keyValue[7] ^ 0xF0);
            }
        }
        // check for 3DES key
        if (keyType == EncryptedData.ETYPE_DES3_CBC_HMAC_SHA1_KD) {
            // fix 3DES key parity
            if (!DESedeKeySpec.isParityAdjusted(keyValue, 0)) {
                keyValue = Des3.parityFix(keyValue);
            }
            // check for weak keys
            byte[] oneKey = new byte[8];
            for (int i=0; i<keyValue.length; i+=8) {
                System.arraycopy(keyValue, i, oneKey, 0, 8);
                if (DESKeySpec.isWeak(oneKey, 0)) {
                    keyValue[i+7] = (byte)(keyValue[i+7] ^ 0xF0);
                }
            }
        }
    } catch (GeneralSecurityException e) {
        KrbCryptoException ke = new KrbCryptoException(e.getMessage());
        ke.initCause(e);
        throw ke;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:50,代碼來源:EncryptionKey.java

示例3: EncryptionKey

import javax.crypto.spec.DESedeKeySpec; //導入方法依賴的package包/類
/**
 * Generates a sub-sessionkey from a given session key.
 */
 // Used in KrbApRep, KrbApReq
EncryptionKey(EncryptionKey key) throws KrbCryptoException {
    // generate random sub-session key
    keyValue = Confounder.bytes(key.keyValue.length);
    for (int i = 0; i < keyValue.length; i++) {
      keyValue[i] ^= key.keyValue[i];
    }
    keyType = key.keyType;

    // check for key parity and weak keys
    try {
        // check for DES key
        if ((keyType == EncryptedData.ETYPE_DES_CBC_MD5) ||
            (keyType == EncryptedData.ETYPE_DES_CBC_CRC)) {
            // fix DES key parity
            if (!DESKeySpec.isParityAdjusted(keyValue, 0)) {
                keyValue = Des.set_parity(keyValue);
            }
            // check for weak key
            if (DESKeySpec.isWeak(keyValue, 0)) {
                keyValue[7] = (byte)(keyValue[7] ^ 0xF0);
            }
        }
        // check for 3DES key
        if (keyType == EncryptedData.ETYPE_DES3_CBC_HMAC_SHA1_KD) {
            // fix 3DES key parity
            if (!DESedeKeySpec.isParityAdjusted(keyValue, 0)) {
                keyValue = Des3.parityFix(keyValue);
            }
            // check for weak keys
            byte[] oneKey = new byte[8];
            for (int i=0; i<keyValue.length; i+=8) {
                System.arraycopy(keyValue, i, oneKey, 0, 8);
                if (DESKeySpec.isWeak(oneKey, 0)) {
                    keyValue[i+7] = (byte)(keyValue[i+7] ^ 0xF0);
                }
            }
        }
    } catch (GeneralSecurityException e) {
        KrbCryptoException ke = new KrbCryptoException(e.getMessage());
        ke.initCause(e);
        throw ke;
    }
}
 
開發者ID:openjdk,項目名稱:jdk7-jdk,代碼行數:48,代碼來源:EncryptionKey.java

示例4: testDESAndDESede

import javax.crypto.spec.DESedeKeySpec; //導入方法依賴的package包/類
private void testDESAndDESede(BigInteger g, BigInteger p)
    throws Exception
{
    DHParameterSpec             dhParams = new DHParameterSpec(p, g, 256);

    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DH", "BC");

    keyGen.initialize(dhParams);

    KeyPair kp = keyGen.generateKeyPair();

    KeyAgreement keyAgreement = KeyAgreement.getInstance("DH", "BC");

    keyAgreement.init(kp.getPrivate());
    keyAgreement.doPhase(kp.getPublic(), true);

    SecretKey key = keyAgreement.generateSecret("DES");

    if (key.getEncoded().length != 8)
    {
        fail("DES length wrong");
    }

    if (!DESKeySpec.isParityAdjusted(key.getEncoded(), 0))
    {
        fail("DES parity wrong");
    }

    key = keyAgreement.generateSecret("DESEDE");

    if (key.getEncoded().length != 24)
    {
        fail("DESEDE length wrong");
    }

    if (!DESedeKeySpec.isParityAdjusted(key.getEncoded(), 0))
    {
        fail("DESEDE parity wrong");
    }

    key = keyAgreement.generateSecret("Blowfish");

    if (key.getEncoded().length != 16)
    {
        fail("Blowfish length wrong");
    }
}
 
開發者ID:NoYouShutup,項目名稱:CryptMeme,代碼行數:48,代碼來源:DHTest.java


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