protected byte[] engineGetEncoded( String format) { if (isASN1FormatString(format) || format.equalsIgnoreCase("X.509")) { return engineGetEncoded(); } return null; }
protected AlgorithmParameterSpec engineGetParameterSpec( Class paramSpec) throws InvalidParameterSpecException { if (paramSpec == null) { throw new NullPointerException("argument to getParameterSpec must not be null"); } return localEngineGetParameterSpec(paramSpec); }
protected Key engineTranslateKey( Key key) throws InvalidKeyException { if (key instanceof GOST3410PublicKey) { return new BCGOST3410PublicKey((GOST3410PublicKey)key); } else if (key instanceof GOST3410PrivateKey) { return new BCGOST3410PrivateKey((GOST3410PrivateKey)key); } throw new InvalidKeyException("key type unknown"); }
public KeyPair generateKeyPair() { if (!initialised) { init(new GOST3410ParameterSpec(CryptoProObjectIdentifiers.gostR3410_94_CryptoPro_A.getId()), CryptoServicesRegistrar.getSecureRandom()); } AsymmetricCipherKeyPair pair = engine.generateKeyPair(); GOST3410PublicKeyParameters pub = (GOST3410PublicKeyParameters)pair.getPublic(); GOST3410PrivateKeyParameters priv = (GOST3410PrivateKeyParameters)pair.getPrivate(); return new KeyPair(new BCGOST3410PublicKey(pub, gost3410Params), new BCGOST3410PrivateKey(priv, gost3410Params)); } }
public boolean equals( Object o) { if (!(o instanceof GOST3410PrivateKey)) { return false; } GOST3410PrivateKey other = (GOST3410PrivateKey)o; return this.getX().equals(other.getX()) && this.getParameters().getPublicKeyParameters().equals(other.getParameters().getPublicKeyParameters()) && this.getParameters().getDigestParamSetOID().equals(other.getParameters().getDigestParamSetOID()) && compareObj(this.getParameters().getEncryptionParamSetOID(), other.getParameters().getEncryptionParamSetOID()); }
protected void engineInit( byte[] params, String format) throws IOException { if (isASN1FormatString(format) || format.equalsIgnoreCase("X.509")) { engineInit(params); } else { throw new IOException("Unknown parameter format " + format); } }
protected PrivateKey engineGeneratePrivate( KeySpec keySpec) throws InvalidKeySpecException { if (keySpec instanceof GOST3410PrivateKeySpec) { return new BCGOST3410PrivateKey((GOST3410PrivateKeySpec)keySpec); } return super.engineGeneratePrivate(keySpec); }
protected PublicKey engineGeneratePublic( KeySpec keySpec) throws InvalidKeySpecException { if (keySpec instanceof GOST3410PublicKeySpec) { return new BCGOST3410PublicKey((GOST3410PublicKeySpec)keySpec); } return super.engineGeneratePublic(keySpec); }
public int hashCode() { return this.getX().hashCode() ^ gost3410Spec.hashCode(); }
public void initialize( AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException { if (!(params instanceof GOST3410ParameterSpec)) { throw new InvalidAlgorithmParameterException("parameter object not a GOST3410ParameterSpec"); } init((GOST3410ParameterSpec)params, random); }
static String publicKeyToString(String algorithm, BigInteger y, GOST3410Parameters gostParams) { StringBuffer buf = new StringBuffer(); String nl = Strings.lineSeparator(); buf.append(algorithm); buf.append(" Public Key [").append(generateKeyFingerprint(y, gostParams)).append("]").append(nl); buf.append(" Y: ").append(y.toString(16)).append(nl); return buf.toString(); }
protected void engineInitSign( PrivateKey privateKey) throws InvalidKeyException { CipherParameters param; if (privateKey instanceof ECKey) { param = ECUtil.generatePrivateKeyParameter(privateKey); } else { param = GOST3410Util.generatePrivateKeyParameter(privateKey); } digest.reset(); if (random != null) { signer.init(true, new ParametersWithRandom(param, random)); } else { signer.init(true, param); } }
protected AlgorithmParameters engineGenerateParameters() { GOST3410ParametersGenerator pGen = new GOST3410ParametersGenerator(); if (random != null) { pGen.init(strength, 2, random); } else { pGen.init(strength, 2, CryptoServicesRegistrar.getSecureRandom()); } GOST3410Parameters p = pGen.generateParameters(); AlgorithmParameters params; try { params = createParametersInstance("GOST3410"); params.init(new GOST3410ParameterSpec(new GOST3410PublicKeyParameterSetSpec(p.getP(), p.getQ(), p.getA()))); } catch (Exception e) { throw new RuntimeException(e.getMessage()); } return params; } }
public String toString() { try { return GOSTUtil.privateKeyToString("GOST3410", x, ((GOST3410PrivateKeyParameters)GOST3410Util.generatePrivateKeyParameter(this)).getParameters()); } catch (InvalidKeyException e) { throw new IllegalStateException(e.getMessage()); // should not be possible } }
public String toString() { try { return GOSTUtil.publicKeyToString("GOST3410", y, ((GOST3410PublicKeyParameters)GOST3410Util.generatePublicKeyParameter(this)).getParameters()); } catch (InvalidKeyException e) { throw new IllegalStateException(e.getMessage()); // should not be possible } }
public void configure(ConfigurableProvider provider) { provider.addAlgorithm("KeyPairGenerator.GOST3410", PREFIX + "KeyPairGeneratorSpi"); provider.addAlgorithm("Alg.Alias.KeyPairGenerator.GOST-3410", "GOST3410"); provider.addAlgorithm("Alg.Alias.KeyPairGenerator.GOST-3410-94", "GOST3410"); provider.addAlgorithm("KeyFactory.GOST3410", PREFIX + "KeyFactorySpi"); provider.addAlgorithm("Alg.Alias.KeyFactory.GOST-3410", "GOST3410"); provider.addAlgorithm("Alg.Alias.KeyFactory.GOST-3410-94", "GOST3410"); provider.addAlgorithm("AlgorithmParameters.GOST3410", PREFIX + "AlgorithmParametersSpi"); provider.addAlgorithm("AlgorithmParameterGenerator.GOST3410", PREFIX + "AlgorithmParameterGeneratorSpi"); registerOid(provider, CryptoProObjectIdentifiers.gostR3410_94, "GOST3410", new KeyFactorySpi()); registerOidAlgorithmParameterGenerator(provider, CryptoProObjectIdentifiers.gostR3410_94, "GOST3410"); provider.addAlgorithm("Signature.GOST3410", PREFIX + "SignatureSpi"); provider.addAlgorithm("Alg.Alias.Signature.GOST-3410", "GOST3410"); provider.addAlgorithm("Alg.Alias.Signature.GOST-3410-94", "GOST3410"); provider.addAlgorithm("Alg.Alias.Signature.GOST3411withGOST3410", "GOST3410"); provider.addAlgorithm("Alg.Alias.Signature.GOST3411WITHGOST3410", "GOST3410"); provider.addAlgorithm("Alg.Alias.Signature.GOST3411WithGOST3410", "GOST3410"); provider.addAlgorithm("Alg.Alias.Signature." + CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94, "GOST3410"); provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator.GOST-3410", "GOST3410"); provider.addAlgorithm("Alg.Alias.AlgorithmParameters.GOST-3410", "GOST3410"); } }
public PrivateKey generatePrivate(PrivateKeyInfo keyInfo) throws IOException { ASN1ObjectIdentifier algOid = keyInfo.getPrivateKeyAlgorithm().getAlgorithm(); if (algOid.equals(CryptoProObjectIdentifiers.gostR3410_94)) { return new BCGOST3410PrivateKey(keyInfo); } else { throw new IOException("algorithm identifier " + algOid + " in key not recognised"); } }
public PublicKey generatePublic(SubjectPublicKeyInfo keyInfo) throws IOException { ASN1ObjectIdentifier algOid = keyInfo.getAlgorithm().getAlgorithm(); if (algOid.equals(CryptoProObjectIdentifiers.gostR3410_94)) { return new BCGOST3410PublicKey(keyInfo); } else { throw new IOException("algorithm identifier " + algOid + " in key not recognised"); } } }
byte[] keyEnc = this.getX().toByteArray(); byte[] keyBytes;
static String privateKeyToString(String algorithm, BigInteger x, GOST3410Parameters gostParams) { StringBuffer buf = new StringBuffer(); String nl = Strings.lineSeparator(); BigInteger y = gostParams.getA().modPow(x, gostParams.getP()); buf.append(algorithm); buf.append(" Private Key [").append(generateKeyFingerprint(y, gostParams)).append("]").append(nl); buf.append(" Y: ").append(y.toString(16)).append(nl); return buf.toString(); }