Ejemplo n.º 1
0
    protected PrivateKey engineGeneratePrivate(KeySpec keySpec) throws InvalidKeySpecException {
      if (keySpec instanceof PKCS8EncodedKeySpec) {
        try {
          return JDKKeyFactory.createPrivateKeyFromDERStream(
              ((PKCS8EncodedKeySpec) keySpec).getEncoded());
        } catch (Exception e) {
          //
          // in case it's just a RSAPrivateKey object...
          //
          try {
            return new JCERSAPrivateCrtKey(
                new RSAPrivateKeyStructure(
                    (ASN1Sequence)
                        new ASN1InputStream(((PKCS8EncodedKeySpec) keySpec).getEncoded())
                            .readObject()));
          } catch (Exception ex) {
            throw new InvalidKeySpecException(ex.toString());
          }
        }
      } else if (keySpec instanceof RSAPrivateCrtKeySpec) {
        return new JCERSAPrivateCrtKey((RSAPrivateCrtKeySpec) keySpec);
      } else if (keySpec instanceof RSAPrivateKeySpec) {
        return new JCERSAPrivateKey((RSAPrivateKeySpec) keySpec);
      }

      throw new InvalidKeySpecException("Unknown KeySpec type: " + keySpec.getClass().getName());
    }
Ejemplo n.º 2
0
    protected PrivateKey engineGeneratePrivate(KeySpec keySpec) throws InvalidKeySpecException {
      if (keySpec instanceof PKCS8EncodedKeySpec) {
        try {
          return JDKKeyFactory.createPrivateKeyFromDERStream(
              ((PKCS8EncodedKeySpec) keySpec).getEncoded());
        } catch (Exception e) {
          throw new InvalidKeySpecException(e.toString());
        }
      }

      throw new InvalidKeySpecException("Unknown KeySpec type: " + keySpec.getClass().getName());
    }
Ejemplo n.º 3
0
    protected PrivateKey engineGeneratePrivate(KeySpec keySpec) throws InvalidKeySpecException {
      if (keySpec instanceof PKCS8EncodedKeySpec) {
        try {
          return JDKKeyFactory.createPrivateKeyFromDERStream(
              ((PKCS8EncodedKeySpec) keySpec).getEncoded());
        } catch (Exception e) {
          throw new InvalidKeySpecException(e.toString());
        }
      }
      // BEGIN android-removed
      // else if (keySpec instanceof GOST3410PrivateKeySpec)
      // {
      //     return new JDKGOST3410PrivateKey((GOST3410PrivateKeySpec)keySpec);
      // }
      // END android-removed

      throw new InvalidKeySpecException("Unknown KeySpec type: " + keySpec.getClass().getName());
    }