本文将介绍string密钥转PrivateKey和PublicKey的详细情况,特别是关于stringpassword的相关信息。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同
本文将介绍string密钥转PrivateKey和PublicKey的详细情况,特别是关于string password的相关信息。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时也将涉及一些关于.net 2.0 不支持 rsa.ImportRSAPrivateKey(privateKey, out _),任何人都可以建议另一种导入自定义私钥的方法、android 支付宝 KeyFactory PrivateKey、c – openSSL:PEM_write_RSAPublicKey和PEM_write_RSA_PUBKEY之间的区别、DuplicatekeyerrorinMySQL(Duplicatekeyname'&a的知识。
本文目录一览:- string密钥转PrivateKey和PublicKey(string password)
- .net 2.0 不支持 rsa.ImportRSAPrivateKey(privateKey, out _),任何人都可以建议另一种导入自定义私钥的方法
- android 支付宝 KeyFactory PrivateKey
- c – openSSL:PEM_write_RSAPublicKey和PEM_write_RSA_PUBKEY之间的区别
- DuplicatekeyerrorinMySQL(Duplicatekeyname'&a
string密钥转PrivateKey和PublicKey(string password)
公钥
private PublicKey getPubKey() {
PublicKey publicKey = null;
try {
String
pubKey="MIGfMA0GDQPwkqCJC68pHH5EBWRUAA4GNAw0d0PKb9ucvucZeo8Yij4/hd+TQ2CL43eQCOPbKiYu3Gz1/6L911CW0GVgpOJ/riO1tHu1U7DCBiQKBgQDIqBZ0tduWNnrin1PIFRVIgbB4x05euEjVAeAQCSqGSIb3lRzKLJcmNUovZ6z5l28HPTTlG+BuwcPQES4XD/Oh6cDt81D3QIDAQAB";
java.security.spec.X509EncodedKeySpec bobPubKeySpec = new java.security.spec.X509EncodedKeySpec(
new BASE64Decoder().decodeBuffer(pubKey));
Java.security.KeyFactory keyFactory;
keyFactory = java.security.KeyFactory.getInstance("RSA");
publicKey = keyFactory.generatePublic(bobPubKeySpec);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (InvalidKeySpecException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return publicKey;
}
私钥
private PrivateKey getPrivateKey() {
PrivateKey privateKey = null;
String priKey = "MIICdQImez/r5jBm6qmicMzxMA6z/WGg/7V1lI/myX4ebMgzWAvoLej23eFX9HjjQf4dmbARf7fskVsXTkN3KSZC6I5ONm0kopcpnMgjjH+9AgMBAAECgYBSh84AoGNBgkqhkiG5+DBAIXkpUZ+B9FYXqZBn4/zrPKfPbB2EVEC+V26glQABMK0S3y2w5+cdvbIasHO7bnsTQKb0OEus23kYuqSJlhhNj45eEz4ptqpNeWRPwQJBAMoodF46gA9w0BAQEdUjW3g1inGKyRdgmFdbf/nJHIiIojl9sctQGPvJzb7DaXLeR7Z3dCuqlgi9qpArsQvSUZ8wQvzpLUNHeiHKPyVGL/Dng6JbS2gIGzsMBCMkvnhhhHZi9QcoJ5jHqWMIF9bJHDZ2m1kY91yXh71w9l/J52wJakI82304KNAkA0bdG+1saYr4/5jyhhQ+0Zn2f7PsJV4hd+x++lm7pNUYSWaQGhB39qOvepxHCBPD/xzdi/gTz6H0i5kCQQCpjcCzogbk9XtS0NMRBADA3GetbUfziG6QSbRJYFAkEAkqGlRnPISELjNtIf25nPfM4OWTJclqOpHNaDVCBKwJqPSUwejHL0r8fPH/pU0bdadbWBNs8Ff8sb9X";
PKCS8EncodedKeySpec priPKCS8;
try {
priPKCS8 = new PKCS8EncodedKeySpec(new BASE64Decoder().decodeBuffer(priKey));
KeyFactory keyf = KeyFactory.getInstance("RSA");
privateKey = keyf.generatePrivate(priPKCS8);
} catch (IOException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (InvalidKeySpecException e) {
e.printStackTrace();
}
return privateKey;
}
.net 2.0 不支持 rsa.ImportRSAPrivateKey(privateKey, out _),任何人都可以建议另一种导入自定义私钥的方法
我已将 XML 格式的 privateKey 传递给 createToken 方法,这解决了我的问题。引用 C# RSA encryption/decryption with transmission。
android 支付宝 KeyFactory PrivateKey
public class SignUtils {
private static final String ALGORITHM = "RSA";
private static final String SIGN_ALGORITHMS = "SHA1WithRSA";
private static final String DEFAULT_CHARSET = "UTF-8";
public static String sign(String content, String privateKey) {
try {
PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(
Base64.decode(privateKey));
KeyFactory keyf = KeyFactory.getInstance(ALGORITHM);
PrivateKey priKey = keyf.generatePrivate(priPKCS8);
java.security.Signature signature = java.security.Signature
.getInstance(SIGN_ALGORITHMS);
signature.initSign(priKey);
signature.update(content.getBytes(DEFAULT_CHARSET));
byte[] signed = signature.sign();
return Base64.encode(signed);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
第一开始,调用 KeyFactory keyf = KeyFactory.getInstance (ALGORITHM); 报错。如下:
java.security.spec.InvalidKeySpecException: java.lang.RuntimeException: error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag
KeyFactory keyf = KeyFactory.getInstance (ALGORITHM, "BC"); 加入了 “BC” 报如下错误:
com.android.org.bouncycastle.jcajce.provider.asymmetric.util.ExtendedInvalidKeySpecException: unable to process key spec: java.lang.ClassCastException: com.android.org.bouncycastle.asn1.DLSequence cannot be cast to com.android.org.bouncycastle.asn1.ASN1Integer
最终因为传入私钥错误。需要重新生成私钥:
私钥的格式大约是这样:
c – openSSL:PEM_write_RSAPublicKey和PEM_write_RSA_PUBKEY之间的区别
int PEM_write_RSAPublicKey(FILE *fp,RSA *x); int PEM_write_RSA_PUBKEY(FILE *fp,RSA *x);
在文档中,我可以看到:
The RSAPublicKey functions process an RSA public key using an RSA
structure. The public key is encoded using a PKCS#1 RSAPublicKey
structure.The RSA_PUBKEY functions also process an RSA public key using an RSA
structure. However the public key is encoded using a
SubjectPublicKeyInfo structure and an error occurs if the public key
is not RSA
但我不明白是什么
SubjectPublicKeyInfo
两种方法之间的基本面差异是什么!
解决方法
DuplicatekeyerrorinMySQL(Duplicatekeyname'&a
the below query is resulting in an error. i created this query in mysql workbench ErrorSQL query:-- ------------------------------------------------------- Table `smsdb`.`IntSupervisor`-- ---------------------------------------------------
the below query is resulting in an error. i created this query in mysql workbench
Error SQL query: -- ----------------------------------------------------- -- Table `smsdb`.`IntSupervisor` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `smsdb`.`IntSupervisor` ( `int_supr_id` VARCHAR( 32 ) NOT NULL , `cent_id` INT NOT NULL , INDEX `fk_IntSupervisor_Person1_idx` ( `int_supr_id` ASC ) , INDEX `fk_IntSupervisor_Center1_idx` ( `cent_id` ASC ) , PRIMARY KEY ( `int_supr_id` ) , CONSTRAINT `fk_parent_id` FOREIGN KEY ( `int_supr_id` ) REFERENCES `smsdb`.`Staff` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT , CONSTRAINT `fk_center_id` FOREIGN KEY ( `cent_id` ) REFERENCES `smsdb`.`Center` (`cent_id` ) ON DELETE CASCADE ON UPDATE RESTRICT ) ENGINE = InnoDB;
I got an error message on execution:
MySQL said: Documentation #1022 - Can''t write; duplicate key in table ''intsupervisor''
If anyone has any ideas on how I can resolve this issue, please guide me in the right direction. Thanks!
Welcome to relational databases in MySQL! ;)
You can''t have two foreign keys named the same thing across the whole query.
PRIMARY KEY ( `int_supr_id` ) ,
CONSTRAINT `fk_parent_id` FOREIGN KEY ( `int_supr_id` )
In the above statement, you can''t redefine the index type on a single column.
So, how do I fix this annoying error?
Based on the structure of the database, you need to remove one of the two lines above. I''m guessing your linking to another table from the one you are creating, so I recommend replacing ...
PRIMARY KEY ( `int_supr_id` ) , CONSTRAINT `fk_parent_id` FOREIGN KEY ( `int_supr_id` )
With the following:
CONSTRAINT `fk_parent_id` FOREIGN KEY ( `int_supr_id` )
(if the above doesn''t work, you likely need to specify a table name for the foreign key)
2.--
-- Table structure for table `payment`
--
DROP TABLE IF EXISTS `payment`;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
CREATE TABLE `payment` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`entry_ID` int(11) NOT NULL,
`account_ID` int(11) NOT NULL,
`amount` double NOT NULL,
`pmt_form` varchar(20) NOT NULL,
`reference` varchar(120) DEFAULT NULL,
`COID` int(11) NOT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `ID` (`ID`),
KEY `FK_PAYMENT_ACCOUNT` (`account_ID`),
KEY `FK_PAYMENT_ENTRY` (`entry_ID`),
CONSTRAINT `FK_PAYMENT_ACCOUNT` FOREIGN KEY (`account_ID`) REFERENCES `account` (`ID`),
CONSTRAINT `FK_PAYMENT_ENTRY` FOREIGN KEY (`entry_ID`)REFERENCES `register_entry` (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
SET character_set_client = @saved_cs_client;
一开始一个是entry_ID 一个是 entry_id 导致报错。后来改为一样 导入数据通过
关于string密钥转PrivateKey和PublicKey和string password的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于.net 2.0 不支持 rsa.ImportRSAPrivateKey(privateKey, out _),任何人都可以建议另一种导入自定义私钥的方法、android 支付宝 KeyFactory PrivateKey、c – openSSL:PEM_write_RSAPublicKey和PEM_write_RSA_PUBKEY之间的区别、DuplicatekeyerrorinMySQL(Duplicatekeyname'&a的相关信息,请在本站寻找。
本文标签: