
net.jsign.jca.JsignJcaProvider Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2023 Emmanuel Bourg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.jsign.jca;
import java.io.InputStream;
import java.security.AccessController;
import java.security.InvalidKeyException;
import java.security.InvalidParameterException;
import java.security.Key;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PrivilegedAction;
import java.security.Provider;
import java.security.Signature;
import java.security.SignatureException;
import java.security.UnrecoverableKeyException;
import java.security.cert.Certificate;
import java.util.Enumeration;
import net.jsign.DigestAlgorithm;
import net.jsign.KeyStoreBuilder;
import net.jsign.KeyStoreType;
/**
* JCA provider using a Jsign keystore and compatible with jarsigner and apksigner.
*
* The provider must be configured with the keystore parameter (the value depends on the keystore type).
* The type of the keystore is one of the names from the {@link KeyStoreType} enum.
*
* Example:
*
* Provider provider = new JsignJcaProvider();
* provider.configure(vaultname)
* KeyStore keystore = KeyStore.getInstance(AZUREKEYVAULT.name(), provider);
* keystore.load(null, accessToken);
*
* PrivateKey key = (PrivateKey) keystore.getKey(alias, null);
*
* Signature signature = Signature.getInstance("SHA256withRSA", provider);
* signature.initSign(key);
* signature.update("Lorem ipsum dolor sit amet".getBytes());
* signature.sign();
*
*
* @since 6.0
*/
public class JsignJcaProvider extends Provider {
private String keystore;
public JsignJcaProvider() {
super("Jsign", 1.0, "Jsign security provider");
AccessController.doPrivileged((PrivilegedAction
© 2015 - 2025 Weber Informatics LLC | Privacy Policy