ExportKey.cpp
上传用户:stc1860
上传日期:2007-01-12
资源大小:234k
文件大小:4k
源码类别:

CA认证

开发平台:

MultiPlatform

  1. /*
  2.  * Copyright (C) 2001 Christian Hohnstaedt.
  3.  *
  4.  *  All rights reserved.
  5.  *
  6.  *
  7.  *  Redistribution and use in source and binary forms, with or without 
  8.  *  modification, are permitted provided that the following conditions are met:
  9.  *
  10.  *  - Redistributions of source code must retain the above copyright notice,
  11.  *    this list of conditions and the following disclaimer.
  12.  *  - Redistributions in binary form must reproduce the above copyright notice,
  13.  *    this list of conditions and the following disclaimer in the documentation
  14.  *    and/or other materials provided with the distribution.
  15.  *  - Neither the name of the author nor the names of its contributors may be 
  16.  *    used to endorse or promote products derived from this software without
  17.  *    specific prior written permission.
  18.  *
  19.  *
  20.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22.  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23.  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24.  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25.  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26.  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  27.  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28.  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  29.  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  30.  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31.  *
  32.  *
  33.  * This program links to software with different licenses from:
  34.  *
  35.  * http://www.openssl.org which includes cryptographic software
  36.  *  written by Eric Young (eay@cryptsoft.com)"
  37.  *
  38.  * http://www.sleepycat.com
  39.  *
  40.  * http://www.trolltech.com
  41.  * 
  42.  *
  43.  *
  44.  * http://www.hohnstaedt.de/xca
  45.  * email: christian@hohnstaedt.de
  46.  *
  47.  * $Id: ExportKey.cpp,v 1.13 2002/10/10 19:40:36 chris Exp $ 
  48.  *
  49.  */                           
  50. #include "ExportKey.h"
  51. ExportKey::ExportKey(QString fname, bool onlypub, 
  52. QWidget *parent, const char *name )
  53. :ExportKey_UI(parent,name,true,0)
  54. {
  55. filename->setText(fname);
  56. setCaption(tr(XCA_TITLE));
  57. onlyPub = onlypub;
  58. exportFormat->insertItem("PEM");
  59. exportFormat->insertItem("DER");
  60. if (onlyPub) {
  61. privFrame->setDisabled(true);
  62. exportPrivate->setDisabled(true);
  63. encryptKey->setDisabled(true);
  64. }
  65. else {
  66. exportPrivate->setChecked(true);
  67. exportFormat->insertItem("PKCS#8");
  68. }
  69. canEncrypt();
  70. }
  71. void ExportKey::chooseFile()
  72. {
  73. QStringList filt;
  74. filt.append(tr("RSA Keys ( *.pem *.der *.pk8 )")); 
  75. filt.append(tr("All Files ( *.* )"));
  76. QString s = "";
  77. QFileDialog *dlg = new QFileDialog(this,0,true);
  78. dlg->setCaption(tr("Save RSA key as"));
  79. dlg->setFilters(filt);
  80. dlg->setMode( QFileDialog::AnyFile );
  81. dlg->setSelection( filename->text() );
  82. if (dlg->exec())
  83. s = dlg->selectedFile();
  84. if (! s.isEmpty()) {
  85. QDir::convertSeparators(s);
  86. filename->setText(s);
  87. }
  88. delete dlg;
  89. }
  90. void ExportKey::canEncrypt() {
  91. CERR("TOGGEL");
  92. if (exportFormat->currentText() == "PKCS#8") {
  93. exportPrivate->setChecked(true);
  94. exportPrivate->setDisabled(true);
  95. encryptKey->setChecked(true);
  96. encryptKey->setDisabled(true);
  97. }
  98. else if (exportFormat->currentText() == "PEM" && !onlyPub) {
  99. exportPrivate->setEnabled(true);
  100.      if (exportPrivate->isChecked()) {
  101. encryptKey->setEnabled(true);
  102. }
  103. else {
  104. encryptKey->setEnabled(false);
  105. }
  106. }
  107. else {
  108. encryptKey->setDisabled(true);
  109. encryptKey->setChecked(false);
  110. exportPrivate->setEnabled(true);
  111. }
  112. if (onlyPub) {
  113. exportPrivate->setChecked(false);
  114. exportPrivate->setDisabled(true);
  115. encryptKey->setChecked(false);
  116. encryptKey->setDisabled(true);
  117. }
  118. }