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


Java OAEPParameterSpec.getPSource方法代码示例

本文整理汇总了Java中javax.crypto.spec.OAEPParameterSpec.getPSource方法的典型用法代码示例。如果您正苦于以下问题:Java OAEPParameterSpec.getPSource方法的具体用法?Java OAEPParameterSpec.getPSource怎么用?Java OAEPParameterSpec.getPSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.crypto.spec.OAEPParameterSpec的用法示例。


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

示例1: engineInit

import javax.crypto.spec.OAEPParameterSpec; //导入方法依赖的package包/类
protected void engineInit(AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException {
    if (!(paramSpec instanceof OAEPParameterSpec)) {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
    OAEPParameterSpec spec = (OAEPParameterSpec) paramSpec;
    mdName = spec.getDigestAlgorithm();
    String mgfName = spec.getMGFAlgorithm();
    if (!mgfName.equalsIgnoreCase("MGF1")) {
        throw new InvalidParameterSpecException("Unsupported mgf " +
            mgfName + "; MGF1 only");
    }
    AlgorithmParameterSpec mgfSpec = spec.getMGFParameters();
    if (!(mgfSpec instanceof MGF1ParameterSpec)) {
        throw new InvalidParameterSpecException("Inappropriate mgf " +
            "parameters; non-null MGF1ParameterSpec only");
    }
    this.mgfSpec = (MGF1ParameterSpec) mgfSpec;
    PSource pSrc = spec.getPSource();
    if (pSrc.getAlgorithm().equals("PSpecified")) {
        p = ((PSource.PSpecified) pSrc).getValue();
    } else {
        throw new InvalidParameterSpecException("Unsupported pSource " +
            pSrc.getAlgorithm() + "; PSpecified only");
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:OAEPParameters.java

示例2: comparePSource

import javax.crypto.spec.OAEPParameterSpec; //导入方法依赖的package包/类
private static boolean comparePSource(OAEPParameterSpec s1,
    OAEPParameterSpec s2) {
    PSource src1 = s1.getPSource();
    PSource src2 = s2.getPSource();
    String alg1 = src1.getAlgorithm();
    String alg2 = src2.getAlgorithm();
    if (alg1.equals(alg2)) {
        // assumes they are PSource.PSpecified
        return Arrays.equals(((PSource.PSpecified) src1).getValue(),
            ((PSource.PSpecified) src2).getValue());
    } else {
        System.out.println("PSource algos: " + alg1 + " vs " + alg2);
        return false;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:TestOAEPParameterSpec.java

示例3: readOAEPParameters

import javax.crypto.spec.OAEPParameterSpec; //导入方法依赖的package包/类
private void readOAEPParameters(OAEPParameterSpec spec)
        throws InvalidAlgorithmParameterException {
    String mgfAlgUpper = spec.getMGFAlgorithm().toUpperCase(Locale.US);
    AlgorithmParameterSpec mgfSpec = spec.getMGFParameters();
    if ((!EvpMdRef.MGF1_ALGORITHM_NAME.equals(mgfAlgUpper)
                && !EvpMdRef.MGF1_OID.equals(mgfAlgUpper))
            || !(mgfSpec instanceof MGF1ParameterSpec)) {
        throw new InvalidAlgorithmParameterException(
                "Only MGF1 supported as mask generation function");
    }

    MGF1ParameterSpec mgf1spec = (MGF1ParameterSpec) mgfSpec;
    String oaepAlgUpper = spec.getDigestAlgorithm().toUpperCase(Locale.US);
    try {
        oaepMd = EvpMdRef.getEVP_MDByJcaDigestAlgorithmStandardName(oaepAlgUpper);
        oaepMdSizeBytes =
                EvpMdRef.getDigestSizeBytesByJcaDigestAlgorithmStandardName(oaepAlgUpper);
        mgf1Md = EvpMdRef.getEVP_MDByJcaDigestAlgorithmStandardName(
                mgf1spec.getDigestAlgorithm());
    } catch (NoSuchAlgorithmException e) {
        throw new InvalidAlgorithmParameterException(e);
    }

    PSource pSource = spec.getPSource();
    if (!"PSpecified".equals(pSource.getAlgorithm())
            || !(pSource instanceof PSource.PSpecified)) {
        throw new InvalidAlgorithmParameterException(
                "Only PSpecified accepted for PSource");
    }
    label = ((PSource.PSpecified) pSource).getValue();
}
 
开发者ID:google,项目名称:conscrypt,代码行数:32,代码来源:OpenSSLCipherRSA.java

示例4: getAlgorithmIdentifier

import javax.crypto.spec.OAEPParameterSpec; //导入方法依赖的package包/类
public AlgorithmIdentifier getAlgorithmIdentifier(ASN1ObjectIdentifier algorithm, AlgorithmParameterSpec algorithmSpec)
    throws InvalidAlgorithmParameterException
{
    if (algorithmSpec instanceof OAEPParameterSpec)
    {
        if (algorithmSpec.equals(OAEPParameterSpec.DEFAULT))
        {
            return new AlgorithmIdentifier(algorithm,
                new RSAESOAEPparams(RSAESOAEPparams.DEFAULT_HASH_ALGORITHM, RSAESOAEPparams.DEFAULT_MASK_GEN_FUNCTION, RSAESOAEPparams.DEFAULT_P_SOURCE_ALGORITHM));
        }
        else
        {
            OAEPParameterSpec oaepSpec = (OAEPParameterSpec)algorithmSpec;
            PSource pSource = oaepSpec.getPSource();

            if (!oaepSpec.getMGFAlgorithm().equals(OAEPParameterSpec.DEFAULT.getMGFAlgorithm()))
            {
                throw new InvalidAlgorithmParameterException("only " + OAEPParameterSpec.DEFAULT.getMGFAlgorithm() + " mask generator supported.");
            }

            AlgorithmIdentifier hashAlgorithm = new DefaultDigestAlgorithmIdentifierFinder().find(oaepSpec.getDigestAlgorithm());
            AlgorithmIdentifier mgf1HashAlgorithm = new DefaultDigestAlgorithmIdentifierFinder().find((((MGF1ParameterSpec)oaepSpec.getMGFParameters()).getDigestAlgorithm()));
            return new AlgorithmIdentifier(algorithm,
                                new RSAESOAEPparams(hashAlgorithm, new AlgorithmIdentifier(PKCSObjectIdentifiers.id_mgf1, mgf1HashAlgorithm),
                                                    new AlgorithmIdentifier(PKCSObjectIdentifiers.id_pSpecified, new DEROctetString(((PSource.PSpecified)pSource).getValue()))));
        }
    }

    throw new InvalidAlgorithmParameterException("unknown parameter spec passed.");
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:31,代码来源:JcaAlgorithmParametersConverter.java

示例5: RSAPadding

import javax.crypto.spec.OAEPParameterSpec; //导入方法依赖的package包/类
private RSAPadding(int type, int paddedSize, SecureRandom random,
        OAEPParameterSpec spec) throws InvalidKeyException,
        InvalidAlgorithmParameterException {
    this.type = type;
    this.paddedSize = paddedSize;
    this.random = random;
    if (paddedSize < 64) {
        // sanity check, already verified in RSASignature/RSACipher
        throw new InvalidKeyException("Padded size must be at least 64");
    }
    switch (type) {
    case PAD_BLOCKTYPE_1:
    case PAD_BLOCKTYPE_2:
        maxDataSize = paddedSize - 11;
        break;
    case PAD_NONE:
        maxDataSize = paddedSize;
        break;
    case PAD_OAEP_MGF1:
        String mdName = "SHA-1";
        String mgfMdName = "SHA-1";
        byte[] digestInput = null;
        try {
            if (spec != null) {
                mdName = spec.getDigestAlgorithm();
                String mgfName = spec.getMGFAlgorithm();
                if (!mgfName.equalsIgnoreCase("MGF1")) {
                    throw new InvalidAlgorithmParameterException
                        ("Unsupported MGF algo: " + mgfName);
                }
                mgfMdName = ((MGF1ParameterSpec)spec.getMGFParameters())
                        .getDigestAlgorithm();
                PSource pSrc = spec.getPSource();
                String pSrcAlgo = pSrc.getAlgorithm();
                if (!pSrcAlgo.equalsIgnoreCase("PSpecified")) {
                    throw new InvalidAlgorithmParameterException
                        ("Unsupported pSource algo: " + pSrcAlgo);
                }
                digestInput = ((PSource.PSpecified) pSrc).getValue();
            }
            md = MessageDigest.getInstance(mdName);
            mgfMd = MessageDigest.getInstance(mgfMdName);
        } catch (NoSuchAlgorithmException e) {
            throw new InvalidKeyException
                    ("Digest " + mdName + " not available", e);
        }
        lHash = getInitialHash(md, digestInput);
        int digestLen = lHash.length;
        maxDataSize = paddedSize - 2 - 2 * digestLen;
        if (maxDataSize <= 0) {
            throw new InvalidKeyException
                    ("Key is too short for encryption using OAEPPadding" +
                     " with " + mdName + " and MGF1" + mgfMdName);
        }
        break;
    default:
        throw new InvalidKeyException("Invalid padding: " + type);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:60,代码来源:RSAPadding.java

示例6: RSAPadding

import javax.crypto.spec.OAEPParameterSpec; //导入方法依赖的package包/类
private RSAPadding(int type, int paddedSize, SecureRandom random,
        OAEPParameterSpec spec) throws InvalidKeyException,
        InvalidAlgorithmParameterException {
    this.type = type;
    this.paddedSize = paddedSize;
    this.random = random;
    if (paddedSize < 64) {
        // sanity check, already verified in RSASignature/RSACipher
        throw new InvalidKeyException("Padded size must be at least 64");
    }
    switch (type) {
    case PAD_BLOCKTYPE_1:
    case PAD_BLOCKTYPE_2:
        maxDataSize = paddedSize - 11;
        break;
    case PAD_NONE:
        maxDataSize = paddedSize;
        break;
    case PAD_OAEP_MGF1:
        String mdName = "SHA-1";
        String mgfMdName = "SHA-1";
        byte[] digestInput = null;
        try {
            if (spec != null) {
                mdName = spec.getDigestAlgorithm();
                String mgfName = spec.getMGFAlgorithm();
                if (!mgfName.equalsIgnoreCase("MGF1")) {
                    throw new InvalidAlgorithmParameterException
                        ("Unsupported MGF algo: " + mgfName);
                }
                mgfMdName = ((MGF1ParameterSpec)spec.getMGFParameters()).getDigestAlgorithm();
                PSource pSrc = spec.getPSource();
                String pSrcAlgo = pSrc.getAlgorithm();
                if (!pSrcAlgo.equalsIgnoreCase("PSpecified")) {
                    throw new InvalidAlgorithmParameterException
                        ("Unsupported pSource algo: " + pSrcAlgo);
                }
                digestInput = ((PSource.PSpecified) pSrc).getValue();
            }
            md = MessageDigest.getInstance(mdName);
            mgfMd = MessageDigest.getInstance(mgfMdName);
        } catch (NoSuchAlgorithmException e) {
            throw new InvalidKeyException
                    ("Digest " + mdName + " not available", e);
        }
        lHash = getInitialHash(md, digestInput);
        int digestLen = lHash.length;
        maxDataSize = paddedSize - 2 - 2 * digestLen;
        if (maxDataSize <= 0) {
            throw new InvalidKeyException
                    ("Key is too short for encryption using OAEPPadding" +
                     " with " + mdName + " and MGF1" + mgfMdName);
        }
        break;
    default:
        throw new InvalidKeyException("Invalid padding: " + type);
    }
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:59,代码来源:RSAPadding.java


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