use of java.security.spec.MGF1ParameterSpec in project jjwt by jwtk.
the class RsaProvider method createPssParameterSpecs.
private static Map<SignatureAlgorithm, PSSParameterSpec> createPssParameterSpecs() {
Map<SignatureAlgorithm, PSSParameterSpec> m = new HashMap<SignatureAlgorithm, PSSParameterSpec>();
MGF1ParameterSpec ps = MGF1ParameterSpec.SHA256;
PSSParameterSpec spec = new PSSParameterSpec(ps.getDigestAlgorithm(), "MGF1", ps, 32, 1);
m.put(SignatureAlgorithm.PS256, spec);
ps = MGF1ParameterSpec.SHA384;
spec = new PSSParameterSpec(ps.getDigestAlgorithm(), "MGF1", ps, 48, 1);
m.put(SignatureAlgorithm.PS384, spec);
ps = MGF1ParameterSpec.SHA512;
spec = new PSSParameterSpec(ps.getDigestAlgorithm(), "MGF1", ps, 64, 1);
m.put(SignatureAlgorithm.PS512, spec);
return m;
}
use of java.security.spec.MGF1ParameterSpec in project robovm by robovm.
the class MGF1ParameterSpecTest method testMGF1ParameterSpec01.
//
// Tests
//
/**
* Test #1 for <code>MGF1ParameterSpec</code> constructor<br>
* Assertion: constructs new <code>MGF1ParameterSpec</code>
* object using valid parameter
*/
public final void testMGF1ParameterSpec01() {
try {
MGF1ParameterSpec pgf = new MGF1ParameterSpec(testAlgName);
assertNotNull(pgf);
assertTrue(pgf instanceof MGF1ParameterSpec);
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
}
use of java.security.spec.MGF1ParameterSpec in project robovm by robovm.
the class MGF1ParameterSpecTest method testGetDigestAlgorithm.
/**
* Test for <code>getDigestAlgorithm</code> method<br>
* Assertion: returns the algorithm name of the message
* digest used by the mask generation function
*/
public final void testGetDigestAlgorithm() {
MGF1ParameterSpec aps = new MGF1ParameterSpec(testAlgName);
assertTrue(testAlgName.equals(aps.getDigestAlgorithm()));
}
use of java.security.spec.MGF1ParameterSpec in project robovm by robovm.
the class CipherSpi method engineInit.
protected void engineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException {
CipherParameters param;
if (params == null || params instanceof OAEPParameterSpec) {
if (key instanceof RSAPublicKey) {
if (privateKeyOnly && opmode == Cipher.ENCRYPT_MODE) {
throw new InvalidKeyException("mode 1 requires RSAPrivateKey");
}
param = RSAUtil.generatePublicKeyParameter((RSAPublicKey) key);
} else if (key instanceof RSAPrivateKey) {
if (publicKeyOnly && opmode == Cipher.ENCRYPT_MODE) {
throw new InvalidKeyException("mode 2 requires RSAPublicKey");
}
param = RSAUtil.generatePrivateKeyParameter((RSAPrivateKey) key);
} else {
throw new InvalidKeyException("unknown key type passed to RSA");
}
if (params != null) {
OAEPParameterSpec spec = (OAEPParameterSpec) params;
paramSpec = params;
if (!spec.getMGFAlgorithm().equalsIgnoreCase("MGF1") && !spec.getMGFAlgorithm().equals(PKCSObjectIdentifiers.id_mgf1.getId())) {
throw new InvalidAlgorithmParameterException("unknown mask generation function specified");
}
if (!(spec.getMGFParameters() instanceof MGF1ParameterSpec)) {
throw new InvalidAlgorithmParameterException("unkown MGF parameters");
}
Digest digest = DigestFactory.getDigest(spec.getDigestAlgorithm());
if (digest == null) {
throw new InvalidAlgorithmParameterException("no match on digest algorithm: " + spec.getDigestAlgorithm());
}
MGF1ParameterSpec mgfParams = (MGF1ParameterSpec) spec.getMGFParameters();
Digest mgfDigest = DigestFactory.getDigest(mgfParams.getDigestAlgorithm());
if (mgfDigest == null) {
throw new InvalidAlgorithmParameterException("no match on MGF digest algorithm: " + mgfParams.getDigestAlgorithm());
}
cipher = new OAEPEncoding(new RSABlindedEngine(), digest, mgfDigest, ((PSource.PSpecified) spec.getPSource()).getValue());
}
} else {
throw new IllegalArgumentException("unknown parameter type.");
}
if (!(cipher instanceof RSABlindedEngine)) {
if (random != null) {
param = new ParametersWithRandom(param, random);
} else {
param = new ParametersWithRandom(param, new SecureRandom());
}
}
bOut.reset();
switch(opmode) {
case Cipher.ENCRYPT_MODE:
case Cipher.WRAP_MODE:
cipher.init(true, param);
break;
case Cipher.DECRYPT_MODE:
case Cipher.UNWRAP_MODE:
cipher.init(false, param);
break;
default:
throw new InvalidParameterException("unknown opmode " + opmode + " passed to RSA");
}
}
use of java.security.spec.MGF1ParameterSpec in project j2objc by google.
the class MGF1ParameterSpecTest method testGetDigestAlgorithm.
/**
* Test for <code>getDigestAlgorithm</code> method<br>
* Assertion: returns the algorithm name of the message
* digest used by the mask generation function
*/
public final void testGetDigestAlgorithm() {
MGF1ParameterSpec aps = new MGF1ParameterSpec(testAlgName);
assertTrue(testAlgName.equals(aps.getDigestAlgorithm()));
}
Aggregations