use of java.security.interfaces.DSAPrivateKey in project keystore-explorer by kaikramer.
the class DViewPrivateKey method populateDialog.
private void populateDialog() throws CryptoException {
KeyInfo keyInfo = KeyPairUtil.getKeyInfo(privateKey);
jtfAlgorithm.setText(keyInfo.getAlgorithm());
Integer keyLength = keyInfo.getSize();
if (keyLength != null) {
jtfKeySize.setText(MessageFormat.format(res.getString("DViewPrivateKey.jtfKeySize.text"), "" + keyLength));
} else {
jtfKeySize.setText(MessageFormat.format(res.getString("DViewPrivateKey.jtfKeySize.text"), "?"));
}
jtfFormat.setText(privateKey.getFormat());
jtfEncoded.setText("0x" + new BigInteger(1, privateKey.getEncoded()).toString(16).toUpperCase());
jtfEncoded.setCaretPosition(0);
if ((privateKey instanceof RSAPrivateKey) || (privateKey instanceof DSAPrivateKey)) {
jbFields.setEnabled(true);
} else {
jbFields.setEnabled(false);
}
}
use of java.security.interfaces.DSAPrivateKey in project keystore-explorer by kaikramer.
the class DExportPrivateKeyPvk method initComponents.
private void initComponents() {
GridBagConstraints gbcLbl = new GridBagConstraints();
gbcLbl.gridx = 0;
gbcLbl.gridwidth = 3;
gbcLbl.gridheight = 1;
gbcLbl.insets = new Insets(5, 5, 5, 5);
gbcLbl.anchor = GridBagConstraints.EAST;
GridBagConstraints gbcEdCtrl = new GridBagConstraints();
gbcEdCtrl.gridx = 3;
gbcEdCtrl.gridwidth = 3;
gbcEdCtrl.gridheight = 1;
gbcEdCtrl.insets = new Insets(5, 5, 5, 5);
gbcEdCtrl.anchor = GridBagConstraints.WEST;
jlKeyType = new JLabel(res.getString("DExportPrivateKeyPvk.jlKeyType.text"));
GridBagConstraints gbc_jlKeyType = (GridBagConstraints) gbcLbl.clone();
gbc_jlKeyType.gridy = 0;
jrbExchange = new JRadioButton(res.getString("DExportPrivateKeyPvk.jrbExchange.text"));
jrbExchange.setToolTipText(res.getString("DExportPrivateKeyPvk.jrbExchange.tooltip"));
PlatformUtil.setMnemonic(jrbExchange, res.getString("DExportPrivateKeyPvk.jrbExchange.mnemonic").charAt(0));
jrbExchange.setSelected(true);
GridBagConstraints gbc_jrbExchange = (GridBagConstraints) gbcEdCtrl.clone();
gbc_jrbExchange.gridy = 0;
jrbSignature = new JRadioButton(res.getString("DExportPrivateKeyPvk.jrbSignature.text"));
jrbSignature.setToolTipText(res.getString("DExportPrivateKeyPvk.jrbSignature.tooltip"));
PlatformUtil.setMnemonic(jrbSignature, res.getString("DExportPrivateKeyPvk.jrbSignature.mnemonic").charAt(0));
GridBagConstraints gbc_jrbSignature = (GridBagConstraints) gbcEdCtrl.clone();
gbc_jrbSignature.gridy = 0;
gbc_jrbSignature.gridx = 6;
ButtonGroup keyTypes = new ButtonGroup();
keyTypes.add(jrbExchange);
keyTypes.add(jrbSignature);
if (privateKey instanceof DSAPrivateKey) {
jrbSignature.setSelected(true);
jrbExchange.setEnabled(false);
jrbSignature.setEnabled(false);
}
jlEncrypt = new JLabel(res.getString("DExportPrivateKeyPvk.jlEncrypt.text"));
GridBagConstraints gbc_jlEncrypt = (GridBagConstraints) gbcLbl.clone();
gbc_jlEncrypt.gridy = 1;
jcbEncrypt = new JCheckBox();
jcbEncrypt.setSelected(true);
jcbEncrypt.setToolTipText(res.getString("DExportPrivateKeyPvk.jcbEncrypt.tooltip"));
GridBagConstraints gbc_jcbEncrypt = (GridBagConstraints) gbcEdCtrl.clone();
gbc_jcbEncrypt.gridy = 1;
jlEncryptionStrength = new JLabel(res.getString("DExportPrivateKeyPvk.jlEncryptionStrength.text"));
GridBagConstraints gbc_jlEncryptionStrength = (GridBagConstraints) gbcLbl.clone();
gbc_jlEncryptionStrength.gridy = 2;
jrbStrong = new JRadioButton(res.getString("DExportPrivateKeyPvk.jrbStrong.text"));
jrbStrong.setToolTipText(res.getString("DExportPrivateKeyPvk.jrbStrong.tooltip"));
PlatformUtil.setMnemonic(jrbStrong, res.getString("DExportPrivateKeyPvk.jrbStrong.mnemonic").charAt(0));
jrbStrong.setSelected(true);
GridBagConstraints gbc_jrbStrong = (GridBagConstraints) gbcEdCtrl.clone();
gbc_jrbStrong.gridy = 2;
jrbWeak = new JRadioButton(res.getString("DExportPrivateKeyPvk.jrbWeak.text"));
jrbWeak.setToolTipText(res.getString("DExportPrivateKeyPvk.jrbWeak.tooltip"));
PlatformUtil.setMnemonic(jrbWeak, res.getString("DExportPrivateKeyPvk.jrbWeak.mnemonic").charAt(0));
GridBagConstraints gbc_jrbWeak = (GridBagConstraints) gbcEdCtrl.clone();
gbc_jrbWeak.gridy = 2;
gbc_jrbWeak.gridx = 6;
ButtonGroup encryptionStrengths = new ButtonGroup();
encryptionStrengths.add(jrbStrong);
encryptionStrengths.add(jrbWeak);
jlPassword = new JLabel(res.getString("DExportPrivateKeyPvk.jlPassword.text"));
GridBagConstraints gbc_jlPassword = (GridBagConstraints) gbcLbl.clone();
gbc_jlPassword.gridy = 3;
if (passwordQualityConfig.getEnabled()) {
if (passwordQualityConfig.getEnforced()) {
jpfPassword = new JPasswordQualityField(15, passwordQualityConfig.getMinimumQuality());
} else {
jpfPassword = new JPasswordQualityField(15);
}
} else {
jpfPassword = new JPasswordField(15);
}
jpfPassword.setToolTipText(res.getString("DExportPrivateKeyPvk.jpqfPassword.tooltip"));
GridBagConstraints gbc_jpfPassword = (GridBagConstraints) gbcEdCtrl.clone();
gbc_jpfPassword.gridy = 3;
gbc_jpfPassword.gridwidth = 6;
jlConfirmPassword = new JLabel(res.getString("DExportPrivateKeyPvk.jlConfirmPassword.text"));
GridBagConstraints gbc_jlConfirmPassword = (GridBagConstraints) gbcLbl.clone();
gbc_jlConfirmPassword.gridy = 4;
jpfConfirmPassword = new JPasswordField(15);
jpfConfirmPassword.setToolTipText(res.getString("DExportPrivateKeyPvk.jpfConfirmPassword.tooltip"));
GridBagConstraints gbc_jpfConfirmPassword = (GridBagConstraints) gbcEdCtrl.clone();
gbc_jpfConfirmPassword.gridy = 4;
gbc_jpfConfirmPassword.gridwidth = 6;
jlExportFile = new JLabel(res.getString("DExportPrivateKeyPvk.jlExportFile.text"));
GridBagConstraints gbc_jlExportFile = (GridBagConstraints) gbcLbl.clone();
gbc_jlExportFile.gridy = 5;
jtfExportFile = new JTextField(30);
jtfExportFile.setToolTipText(res.getString("DExportPrivateKeyPvk.jtfExportFile.tooltip"));
GridBagConstraints gbc_jtfExportFile = (GridBagConstraints) gbcEdCtrl.clone();
gbc_jtfExportFile.gridy = 5;
gbc_jtfExportFile.gridwidth = 6;
jbBrowse = new JButton(res.getString("DExportPrivateKeyPvk.jbBrowse.text"));
jbBrowse.setToolTipText(res.getString("DExportPrivateKeyPvk.jbBrowse.tooltip"));
PlatformUtil.setMnemonic(jbBrowse, res.getString("DExportPrivateKeyPvk.jbBrowse.mnemonic").charAt(0));
GridBagConstraints gbc_jbBrowse = (GridBagConstraints) gbcEdCtrl.clone();
gbc_jbBrowse.gridy = 5;
gbc_jbBrowse.gridx = 9;
jbBrowse.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
try {
CursorUtil.setCursorBusy(DExportPrivateKeyPvk.this);
browsePressed();
} finally {
CursorUtil.setCursorFree(DExportPrivateKeyPvk.this);
}
}
});
jpOptions = new JPanel(new GridBagLayout());
jpOptions.setBorder(new CompoundBorder(new CompoundBorder(new EmptyBorder(5, 5, 5, 5), new EtchedBorder()), new EmptyBorder(5, 5, 5, 5)));
jpOptions.add(jlKeyType, gbc_jlKeyType);
jpOptions.add(jrbExchange, gbc_jrbExchange);
jpOptions.add(jrbSignature, gbc_jrbSignature);
jpOptions.add(jlEncrypt, gbc_jlEncrypt);
jpOptions.add(jcbEncrypt, gbc_jcbEncrypt);
jpOptions.add(jrbStrong, gbc_jrbStrong);
jpOptions.add(jrbWeak, gbc_jrbWeak);
jpOptions.add(jlEncryptionStrength, gbc_jlEncryptionStrength);
jpOptions.add(jlEncryptionStrength, gbc_jlEncryptionStrength);
jpOptions.add(jlPassword, gbc_jlPassword);
jpOptions.add(jpfPassword, gbc_jpfPassword);
jpOptions.add(jlConfirmPassword, gbc_jlConfirmPassword);
jpOptions.add(jpfConfirmPassword, gbc_jpfConfirmPassword);
jpOptions.add(jlExportFile, gbc_jlExportFile);
jpOptions.add(jtfExportFile, gbc_jtfExportFile);
jpOptions.add(jbBrowse, gbc_jbBrowse);
jcbEncrypt.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent evt) {
if (jcbEncrypt.isSelected()) {
jrbStrong.setEnabled(true);
jrbWeak.setEnabled(true);
jpfPassword.setEnabled(true);
jpfConfirmPassword.setEnabled(true);
} else {
jrbStrong.setEnabled(false);
jrbWeak.setEnabled(false);
jpfPassword.setEnabled(false);
if (jpfPassword instanceof JPasswordQualityField) {
((JPasswordQualityField) jpfPassword).setText("");
} else {
((JPasswordField) jpfPassword).setText("");
}
jpfConfirmPassword.setEnabled(false);
jpfConfirmPassword.setText("");
}
}
});
jbExport = new JButton(res.getString("DExportPrivateKeyPvk.jbExport.text"));
PlatformUtil.setMnemonic(jbExport, res.getString("DExportPrivateKeyPvk.jbExport.mnemonic").charAt(0));
jbExport.setToolTipText(res.getString("DExportPrivateKeyPvk.jbExport.tooltip"));
jbExport.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
try {
CursorUtil.setCursorBusy(DExportPrivateKeyPvk.this);
exportPressed();
} finally {
CursorUtil.setCursorFree(DExportPrivateKeyPvk.this);
}
}
});
jbCancel = new JButton(res.getString("DExportPrivateKeyPvk.jbCancel.text"));
jbCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
cancelPressed();
}
});
jbCancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), CANCEL_KEY);
jbCancel.getActionMap().put(CANCEL_KEY, new AbstractAction() {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent evt) {
cancelPressed();
}
});
jpButtons = PlatformUtil.createDialogButtonPanel(jbExport, jbCancel, false);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(jpOptions, BorderLayout.CENTER);
getContentPane().add(jpButtons, BorderLayout.SOUTH);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent evt) {
closeDialog();
}
});
setTitle(MessageFormat.format(res.getString("DExportPrivateKeyPvk.Title"), entryAlias));
setResizable(false);
getRootPane().setDefaultButton(jbExport);
populateExportFileName();
pack();
}
use of java.security.interfaces.DSAPrivateKey in project i2p.i2p by i2p.
the class SigUtil method fromJavaKey.
/**
* Use if SigType is unknown.
* For efficiency, use fromJavakey(pk, type) if type is known.
*
* @param pk JAVA key!
* @throws IllegalArgumentException on unknown type
* @since 0.9.18
*/
public static SigningPrivateKey fromJavaKey(PrivateKey pk) throws GeneralSecurityException {
if (pk instanceof DSAPrivateKey) {
return fromJavaKey((DSAPrivateKey) pk);
}
if (pk instanceof ECPrivateKey) {
ECPrivateKey k = (ECPrivateKey) pk;
AlgorithmParameterSpec spec = k.getParams();
SigType type;
if (spec.equals(SigType.ECDSA_SHA256_P256.getParams()))
type = SigType.ECDSA_SHA256_P256;
else if (spec.equals(SigType.ECDSA_SHA384_P384.getParams()))
type = SigType.ECDSA_SHA384_P384;
else if (spec.equals(SigType.ECDSA_SHA512_P521.getParams()))
type = SigType.ECDSA_SHA512_P521;
else
throw new IllegalArgumentException("Unknown EC type");
return fromJavaKey(k, type);
}
if (pk instanceof EdDSAPrivateKey) {
return fromJavaKey((EdDSAPrivateKey) pk, SigType.EdDSA_SHA512_Ed25519);
}
if (pk instanceof RSAPrivateKey) {
RSAPrivateKey k = (RSAPrivateKey) pk;
int sz = k.getModulus().bitLength();
SigType type;
if (sz <= ((RSAKeyGenParameterSpec) SigType.RSA_SHA256_2048.getParams()).getKeysize())
type = SigType.RSA_SHA256_2048;
else if (sz <= ((RSAKeyGenParameterSpec) SigType.RSA_SHA384_3072.getParams()).getKeysize())
type = SigType.RSA_SHA384_3072;
else if (sz <= ((RSAKeyGenParameterSpec) SigType.RSA_SHA512_4096.getParams()).getKeysize())
type = SigType.RSA_SHA512_4096;
else
throw new IllegalArgumentException("Unknown RSA type");
return fromJavaKey(k, type);
}
throw new IllegalArgumentException("Unknown type: " + pk.getClass());
}
use of java.security.interfaces.DSAPrivateKey in project i2p.i2p by i2p.
the class SigUtil method toJavaDSAKey.
public static DSAPrivateKey toJavaDSAKey(SigningPrivateKey pk) throws GeneralSecurityException {
KeyFactory kf = KeyFactory.getInstance("DSA");
// x p q g
KeySpec ks = new DSAPrivateKeySpec(new NativeBigInteger(1, pk.getData()), CryptoConstants.dsap, CryptoConstants.dsaq, CryptoConstants.dsag);
return (DSAPrivateKey) kf.generatePrivate(ks);
}
use of java.security.interfaces.DSAPrivateKey in project jruby-openssl by jruby.
the class PKeyDSA method syssign.
// ossl_dsa_sign
@JRubyMethod
public IRubyObject syssign(IRubyObject data) {
final Ruby runtime = getRuntime();
DSAPrivateKey privateKey;
if ((privateKey = this.privateKey) == null) {
throw newDSAError(runtime, "Private DSA key needed!");
}
try {
// DSS1
ByteList sign = sign("NONEwithDSA", privateKey, data.convertToString().getByteList());
return RubyString.newString(runtime, sign);
} catch (GeneralSecurityException ex) {
throw newDSAError(runtime, ex.getMessage());
}
}
Aggregations