Package java.security

Examples of java.security.PrivateKey


      repository.setKeyStorePath("test.jks");
      repository.setKeyStorePassword("password");
      repository.setUseDns(false);
      repository.start();

      PrivateKey privateKey = repository.getKeyStore().getPrivateKey("test._domainKey.samplezone.org");
      if (privateKey == null) throw new Exception("Private Key is null!!!");
      PublicKey publicKey = repository.getKeyStore().getPublicKey("test._domainKey.samplezone.org");
      keys = new KeyPair(publicKey, privateKey);

      KeyPair keyPair = KeyPairGenerator.getInstance("RSA").generateKeyPair();
View Full Code Here


      } else if(args[0].equals("--sign") && args.length==3) {
    CryptoLib cl = new CryptoLib();
    CharBuffer privKeyBuffer = new CharBuffer(new File(args[1]));
    byte[] privKeyByteBuffer = Base64Order.standardCoder.decode(privKeyBuffer.toString());
    PrivateKey privKey = cl.getPrivateKeyFromBytes(privKeyByteBuffer);

    FileInputStream dataStream = new FileInputStream(args[2]);

    byte[] signBuffer = cl.getSignature(privKey, dataStream);
    FileWriter signFile = new FileWriter(args[2] + ".sig");
View Full Code Here

           
            String privateKeyFileName = path + "new_"+keyAlgorithmName+"="+provider+".privatekey";
            //String privateKeyFileName = path + "new_RSA=BC.privatekey";
           
           
            PrivateKey privKey = SOSKeyGenerator.getPrivateKeyFromFile(privateKeyFileName);
           
           
            //System.out.println("privKey Length : "+privKey.getEncoded().length);
           
           
            String certFile = path + privKey.getAlgorithm()+"("+provider+")="+signatureAlgo+".cer";
            //String certFile = path + "RSA(BC)=SHA1.cer";
           
           
            Certificate[] chain = SOSCertificate.getCertificateChain(certFile);

           
            SOSPDFSignatur.setReason("Das ist eine Test signatur");
            SOSPDFSignatur.setContact("al@sos-berlin.com");
            SOSPDFSignatur.setLocation("Berlin");

            String signPdfFile = privKey.getAlgorithm()+"("+provider+")="+signatureAlgo+".pdf";
           
            SOSPDFSignatur.createSignatur(privKey, chain,
                    path + "scheduler_install.pdf", path + signPdfFile);

            System.out.println("Sign. PDF wurde erstellt");
View Full Code Here

       
        try {
           
       
            PrivateKey privKey = SOSKeyGenerator.getPrivateKeyFromFile(privateKeyFileName);
            PublicKey pubKey   = SOSKeyGenerator.getPublicKeyFromFile(publicKeyFileName);
           
           
            SOSCertificate.setHashAlgorithm(SOSCertificate.SHA1);
            //SOSCertificate.setHashAlgorithm(SOSCertificate.MD2);
            //SOSCertificate.setHashAlgorithm(SOSCertificate.MD5);
           
            //OU,DC=com
            // ohne CN bei SubjectDN - zeigt Signed by Unknown
           
            // ausgestellt f�r
            //SOSCertificate.setSubjectDN("CN=Robert Ehrlich,C=DE,O=APL/SOS");
            // wenn sich subject von issuer unterscheiden dann ...
            SOSCertificate.setSubjectDN("CN=Andreas Liebert,C=DE,O=APL/SOS");
            //ausgestellt von
            SOSCertificate.setIssuerDN("CN=Andreas Liebert,C=DE,O=APL/SOS");
            SOSCertificate.setSerialNumber(BigInteger.valueOf(100));
           
            String certFile = privKey.getAlgorithm()+"("+provider+")="+SOSCertificate.getHashAlgorithm()+".cer";
           
            SOSCertificate.generateCertificate(privKey, pubKey, path + certFile);
           
            System.out.println("Zertifikate wurde erstellt");
            System.out.println("privKey = "+privateKeyFileName);
View Full Code Here

        if (SOSKeyGenerator.provider == null) { throw new Exception("Provider is null"); }
        if (SOSKeyGenerator.keyAlgorithmName == null) { throw new Exception(
                "keyAlgorithmName is null"); }
       

        PrivateKey priv = null;

        try {
            if (SOSKeyGenerator.provider.equalsIgnoreCase("BC")
                    && Security.getProvider("BC") == null) {
                Provider bp = new org.bouncycastle.jce.provider.BouncyCastleProvider();
View Full Code Here

                + provider + ".privatekey";
        String publicKeyFileName = path + "new_" + keyAlgorithmName + "="
                + provider + ".publickey";

        try {
            PrivateKey privKey = SOSKeyGenerator
                    .getPrivateKeyFromFile(privateKeyFileName);

            SOSSignature.setHashAlgorithm(SOSSignature.SHA1);
            SOSSignature.setProvider(provider);

            System.out.println(privKey.getFormat());

            //Signatur Datei erstellen
            SOSSignature.signToFile(fileToSign, signFile, privKey);

            // Signatur verifizieren
View Full Code Here

   
    final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
   
    final PKCS8EncodedKeySpec privSpec = new PKCS8EncodedKeySpec(privKeyBytes);
   
    final PrivateKey privateKey = keyFactory.generatePrivate(privSpec);
   
    this.digester = MessageDigest.getInstance("sha-256");
   
    this.signer = Signature.getInstance("SHA256withRSA");
    this.signer.initSign(privateKey);
View Full Code Here

    is.close();

    // get my private key
    KeyStore.PasswordProtection protection = new KeyStore.PasswordProtection(password);
    KeyStore.PrivateKeyEntry pkEntry = (KeyStore.PrivateKeyEntry) ks.getEntry(antProp.getProperty("keystore.alias"), protection);
    PrivateKey key = pkEntry.getPrivateKey();

    signer = Signature.getInstance("SHA1withRSA");
    signer.initSign(key);
  }
View Full Code Here

      CertAndKeyGen keypair;
      keypair = new CertAndKeyGen(keyAlgName, sigAlgName, providerName);

      keypair.generate(keysize);

      PrivateKey privKey = keypair.getPrivateKey();
      X500Name x500name = new X500Name("CN=" + name);
     
      X509Certificate cert
        = keypair.getSelfCertificate(x500name, days * 24 * 3600);

 
View Full Code Here

        Document document = builder.parse(sourceDocument);
       
        // Set up the Key
        KeyPairGenerator rsaKeygen = KeyPairGenerator.getInstance("RSA");
        KeyPair kp = rsaKeygen.generateKeyPair();
        PrivateKey priv = kp.getPrivate();
        PublicKey pub = kp.getPublic();

        // Generate a traffic key
        KeyGenerator keygen = KeyGenerator.getInstance("AES");
        keygen.init(256);
View Full Code Here

TOP

Related Classes of java.security.PrivateKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.