Java Code Examples for javax.crypto.spec.OAEPParameterSpec#getMGFAlgorithm()
The following examples show how to use
javax.crypto.spec.OAEPParameterSpec#getMGFAlgorithm() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestOAEPParameterSpec.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
private static boolean compareMGF(OAEPParameterSpec s1, OAEPParameterSpec s2) { String alg1 = s1.getMGFAlgorithm(); String alg2 = s2.getMGFAlgorithm(); if (alg1.equals(alg2)) { MGF1ParameterSpec mp1 = (MGF1ParameterSpec)s1.getMGFParameters(); MGF1ParameterSpec mp2 = (MGF1ParameterSpec)s2.getMGFParameters(); alg1 = mp1.getDigestAlgorithm(); alg2 = mp2.getDigestAlgorithm(); if (alg1.equals(alg2)) { return true; } else { System.out.println("MGF's MD algos: " + alg1 + " vs " + alg2); return false; } } else { System.out.println("MGF algos: " + alg1 + " vs " + alg2); return false; } }
Example 2
Source File: TestOAEPParameterSpec.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private static boolean compareMGF(OAEPParameterSpec s1, OAEPParameterSpec s2) { String alg1 = s1.getMGFAlgorithm(); String alg2 = s2.getMGFAlgorithm(); if (alg1.equals(alg2)) { MGF1ParameterSpec mp1 = (MGF1ParameterSpec)s1.getMGFParameters(); MGF1ParameterSpec mp2 = (MGF1ParameterSpec)s2.getMGFParameters(); alg1 = mp1.getDigestAlgorithm(); alg2 = mp2.getDigestAlgorithm(); if (alg1.equals(alg2)) { return true; } else { System.out.println("MGF's MD algos: " + alg1 + " vs " + alg2); return false; } } else { System.out.println("MGF algos: " + alg1 + " vs " + alg2); return false; } }
Example 3
Source File: TestOAEPParameterSpec.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
private static boolean compareMGF(OAEPParameterSpec s1, OAEPParameterSpec s2) { String alg1 = s1.getMGFAlgorithm(); String alg2 = s2.getMGFAlgorithm(); if (alg1.equals(alg2)) { MGF1ParameterSpec mp1 = (MGF1ParameterSpec)s1.getMGFParameters(); MGF1ParameterSpec mp2 = (MGF1ParameterSpec)s2.getMGFParameters(); alg1 = mp1.getDigestAlgorithm(); alg2 = mp2.getDigestAlgorithm(); if (alg1.equals(alg2)) { return true; } else { System.out.println("MGF's MD algos: " + alg1 + " vs " + alg2); return false; } } else { System.out.println("MGF algos: " + alg1 + " vs " + alg2); return false; } }
Example 4
Source File: TestOAEPParameterSpec.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
private static boolean compareMGF(OAEPParameterSpec s1, OAEPParameterSpec s2) { String alg1 = s1.getMGFAlgorithm(); String alg2 = s2.getMGFAlgorithm(); if (alg1.equals(alg2)) { MGF1ParameterSpec mp1 = (MGF1ParameterSpec)s1.getMGFParameters(); MGF1ParameterSpec mp2 = (MGF1ParameterSpec)s2.getMGFParameters(); alg1 = mp1.getDigestAlgorithm(); alg2 = mp2.getDigestAlgorithm(); if (alg1.equals(alg2)) { return true; } else { System.out.println("MGF's MD algos: " + alg1 + " vs " + alg2); return false; } } else { System.out.println("MGF algos: " + alg1 + " vs " + alg2); return false; } }
Example 5
Source File: TestOAEPParameterSpec.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
private static boolean compareMGF(OAEPParameterSpec s1, OAEPParameterSpec s2) { String alg1 = s1.getMGFAlgorithm(); String alg2 = s2.getMGFAlgorithm(); if (alg1.equals(alg2)) { MGF1ParameterSpec mp1 = (MGF1ParameterSpec)s1.getMGFParameters(); MGF1ParameterSpec mp2 = (MGF1ParameterSpec)s2.getMGFParameters(); alg1 = mp1.getDigestAlgorithm(); alg2 = mp2.getDigestAlgorithm(); if (alg1.equals(alg2)) { return true; } else { System.out.println("MGF's MD algos: " + alg1 + " vs " + alg2); return false; } } else { System.out.println("MGF algos: " + alg1 + " vs " + alg2); return false; } }
Example 6
Source File: TestOAEPParameterSpec.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
private static boolean compareMGF(OAEPParameterSpec s1, OAEPParameterSpec s2) { String alg1 = s1.getMGFAlgorithm(); String alg2 = s2.getMGFAlgorithm(); if (alg1.equals(alg2)) { MGF1ParameterSpec mp1 = (MGF1ParameterSpec)s1.getMGFParameters(); MGF1ParameterSpec mp2 = (MGF1ParameterSpec)s2.getMGFParameters(); alg1 = mp1.getDigestAlgorithm(); alg2 = mp2.getDigestAlgorithm(); if (alg1.equals(alg2)) { return true; } else { System.out.println("MGF's MD algos: " + alg1 + " vs " + alg2); return false; } } else { System.out.println("MGF algos: " + alg1 + " vs " + alg2); return false; } }
Example 7
Source File: TestOAEPParameterSpec.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
private static boolean compareMGF(OAEPParameterSpec s1, OAEPParameterSpec s2) { String alg1 = s1.getMGFAlgorithm(); String alg2 = s2.getMGFAlgorithm(); if (alg1.equals(alg2)) { MGF1ParameterSpec mp1 = (MGF1ParameterSpec)s1.getMGFParameters(); MGF1ParameterSpec mp2 = (MGF1ParameterSpec)s2.getMGFParameters(); alg1 = mp1.getDigestAlgorithm(); alg2 = mp2.getDigestAlgorithm(); if (alg1.equals(alg2)) { return true; } else { System.out.println("MGF's MD algos: " + alg1 + " vs " + alg2); return false; } } else { System.out.println("MGF algos: " + alg1 + " vs " + alg2); return false; } }
Example 8
Source File: TestOAEPParameterSpec.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private static boolean compareMGF(OAEPParameterSpec s1, OAEPParameterSpec s2) { String alg1 = s1.getMGFAlgorithm(); String alg2 = s2.getMGFAlgorithm(); if (alg1.equals(alg2)) { MGF1ParameterSpec mp1 = (MGF1ParameterSpec)s1.getMGFParameters(); MGF1ParameterSpec mp2 = (MGF1ParameterSpec)s2.getMGFParameters(); alg1 = mp1.getDigestAlgorithm(); alg2 = mp2.getDigestAlgorithm(); if (alg1.equals(alg2)) { return true; } else { System.out.println("MGF's MD algos: " + alg1 + " vs " + alg2); return false; } } else { System.out.println("MGF algos: " + alg1 + " vs " + alg2); return false; } }
Example 9
Source File: OAEPParameters.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
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"); } }
Example 10
Source File: OAEPParameters.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
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"); } }
Example 11
Source File: OAEPParameters.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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"); } }
Example 12
Source File: OAEPParameters.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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"); } }
Example 13
Source File: OAEPParameters.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
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"); } }
Example 14
Source File: OAEPParameters.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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"); } }
Example 15
Source File: OAEPParameters.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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"); } }
Example 16
Source File: RSAPadding.java From hottub with GNU General Public License v2.0 | 4 votes |
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); } }
Example 17
Source File: RSAPadding.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
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 = mdName; 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); mgf = new MGF1(mgfMdName); } catch (NoSuchAlgorithmException e) { throw new InvalidKeyException("Digest 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 " + mgf.getName()); } break; default: throw new InvalidKeyException("Invalid padding: " + type); } }
Example 18
Source File: RSAPadding.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
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); } }
Example 19
Source File: RSAPadding.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
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); } }
Example 20
Source File: RSAPadding.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
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); } }