Examples of KeySpec


Examples of java.security.spec.KeySpec

   public LoginCredentials apply(@Nullable PasswordDataAndPrivateKey dataAndKey) {
      if (dataAndKey == null)
         return null;

      try {
         KeySpec keySpec = Pems.privateKeySpec(dataAndKey.getPrivateKey());
         KeyFactory kf = crypto.rsaKeyFactory();
         PrivateKey privKey = kf.generatePrivate(keySpec);

         Cipher cipher = crypto.cipher("RSA");
         cipher.init(Cipher.DECRYPT_MODE, privKey);
View Full Code Here

Examples of java.security.spec.KeySpec

    dssKPG.initialize(512);
    KeyPair kp = dssKPG.generateKeyPair();
    harness.check(kp != null, "MUST generate valid DSS keypair");

    PublicKey p1, p2, p3;
    KeySpec spec1, spec2;
    PrivateKey p4, p5, p6;
    String msg;

    p1 = kp.getPublic();
    try
View Full Code Here

Examples of java.security.spec.KeySpec

    rsaKPG.initialize(1024);
    KeyPair kp = rsaKPG.generateKeyPair();
    harness.check(kp != null, "MUST generate valid RSA keypair");

    PublicKey p1, p2, p3;
    KeySpec spec1, spec2;
    PrivateKey p4, p5, p6;
    String msg;

    p1 = kp.getPublic();
    try
View Full Code Here

Examples of java.security.spec.KeySpec

    dhKPG.initialize(512);
    KeyPair kp = dhKPG.generateKeyPair();
    harness.check(kp != null, "MUST generate valid DH keypair");

    PublicKey p1, p2, p3;
    KeySpec spec1, spec2;
    PrivateKey p4, p5, p6;
    String msg;

    p1 = kp.getPublic();
    try
View Full Code Here

Examples of java.security.spec.KeySpec

    } else if (key != null && key.length == 24) {
      _triple = true;
    } else {
      throw new IllegalArgumentException("Key must be 8 or 24 bytes");
    }
    KeySpec keySpec = _triple ?
        (KeySpec) new DESedeKeySpec(key) :
        (KeySpec) new DESKeySpec(key);
    _key = SecretKeyFactory.getInstance(_triple ? "DESede" : "DES").generateSecret(keySpec);
  }
View Full Code Here

Examples of java.security.spec.KeySpec

  public String encryptPassword(final String password, final String key)
      throws GeneralSecurityException, UnsupportedEncodingException
  {
    final SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
    final KeySpec spec = new PBEKeySpec(key.toCharArray(), SALT, 1024, 128);
    final SecretKey tmp = factory.generateSecret(spec);
    final SecretKey secret = new SecretKeySpec(tmp.getEncoded(), "AES");
    return encryptPassword(password, secret, "AES/CBC/PKCS5PADDING");
  }
View Full Code Here

Examples of java.security.spec.KeySpec

  public String decryptPassword(final String password,
                                final String key) throws UnsupportedEncodingException, GeneralSecurityException
  {
    final SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
    final KeySpec spec = new PBEKeySpec(key.toCharArray(), SALT, 1024, 128);
    final SecretKey tmp = factory.generateSecret(spec);
    final SecretKey secret = new SecretKeySpec(tmp.getEncoded(), "AES");
    return decryptPassword(password, secret, "AES/CBC/PKCS5PADDING");
  }
View Full Code Here

Examples of java.security.spec.KeySpec

    return bytes;
  }
 
  public static DHPublicKey bytesToPublicKey(DHParameterSpec parameterSpec, byte[] bytes){
    /* Set Y (public key), P and G values. */
    KeySpec keySpec = new DHPublicKeySpec(
      bytesToBigInteger(bytes),
      parameterSpec.getP(),
      parameterSpec.getG()
    );
   
View Full Code Here

Examples of java.security.spec.KeySpec

    return null;
  }
 
  public static DHPrivateKey bytesToPrivateKey(DHParameterSpec parameterSpec, byte[] bytes){
    /* Set X (private key), P and G values. */
    KeySpec keySpec = new DHPrivateKeySpec(
      bytesToBigInteger(bytes),
      parameterSpec.getP(),
      parameterSpec.getG()
    );
   
View Full Code Here

Examples of java.security.spec.KeySpec

        ASN1Sequence    crmfSeq = (ASN1Sequence) in.readObject();
        ASN1Sequence reqSeq =  (ASN1Sequence) ((ASN1Sequence) crmfSeq.getObjectAt(0)).getObjectAt(0);
        CertRequest certReq = new CertRequest( reqSeq );
        SubjectPublicKeyInfo pKeyInfo = certReq.getCertTemplate().getPublicKey();
        KeyFactory keyFact = KeyFactory.getInstance("RSA", "BC");
        KeySpec keySpec = new X509EncodedKeySpec( pKeyInfo.getEncoded() );
        PublicKey pubKey = keyFact.generatePublic(keySpec); // just check it's ok
        imsg = new SimpleRequestMessage(pubKey, username, password);
        // a simple crmf is not a complete PKI message, as desired by the CrmfRequestMessage class
        //PKIMessage msg = PKIMessage.getInstance(new ASN1InputStream(new ByteArrayInputStream(request)).readObject());
        //CrmfRequestMessage reqmsg = new CrmfRequestMessage(msg, null, true, null);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.