コード例 #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());
    }
コード例 #2
0
    protected PublicKey engineGeneratePublic(KeySpec keySpec) throws InvalidKeySpecException {
      if (keySpec instanceof X509EncodedKeySpec) {
        try {
          return JDKKeyFactory.createPublicKeyFromDERStream(
              ((X509EncodedKeySpec) keySpec).getEncoded());
        } catch (Exception e) {
          throw new InvalidKeySpecException(e.toString());
        }
      }

      throw new InvalidKeySpecException("Unknown KeySpec type: " + keySpec.getClass().getName());
    }
コード例 #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());
        }
      } else if (keySpec instanceof DSAPrivateKeySpec) {
        return new JDKDSAPrivateKey((DSAPrivateKeySpec) keySpec);
      }

      throw new InvalidKeySpecException("Unknown KeySpec type: " + keySpec.getClass().getName());
    }
コード例 #4
0
    protected PublicKey engineGeneratePublic(KeySpec keySpec) throws InvalidKeySpecException {
      if (keySpec instanceof X509EncodedKeySpec) {
        try {
          return JDKKeyFactory.createPublicKeyFromDERStream(
              ((X509EncodedKeySpec) keySpec).getEncoded());
        } catch (Exception e) {
          throw new InvalidKeySpecException(e.toString());
        }
      }
      // BEGIN android-removed
      // else if (keySpec instanceof GOST3410PublicKeySpec)
      // {
      //     return new JDKGOST3410PublicKey((GOST3410PublicKeySpec)keySpec);
      // }
      // END android-removed

      throw new InvalidKeySpecException("Unknown KeySpec type: " + keySpec.getClass().getName());
    }
コード例 #5
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 ECPrivateKeySpec)
      // {
      //     return new JCEECPrivateKey(algorithm, (ECPrivateKeySpec)keySpec);
      // }
      // else if (keySpec instanceof java.security.spec.ECPrivateKeySpec)
      // {
      //     return new JCEECPrivateKey(algorithm, (java.security.spec.ECPrivateKeySpec)keySpec);
      // }
      // END android-removed

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