org.bouncycastle.asn1.x9.X962Parameters Java Examples
The following examples show how to use
org.bouncycastle.asn1.x9.X962Parameters.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BCECUtil.java From gmhelper with Apache License 2.0 | 5 votes |
/** * 将SEC1标准的私钥字节流恢复为PKCS8标准的字节流 * * @param sec1Key * @return * @throws IOException */ public static byte[] convertECPrivateKeySEC1ToPKCS8(byte[] sec1Key) throws IOException { /** * 参考org.bouncycastle.asn1.pkcs.PrivateKeyInfo和 * org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey,逆向拼装 */ X962Parameters params = getDomainParametersFromName(SM2Util.JDK_EC_SPEC, false); ASN1OctetString privKey = new DEROctetString(sec1Key); ASN1EncodableVector v = new ASN1EncodableVector(); v.add(new ASN1Integer(0)); //版本号 v.add(new AlgorithmIdentifier(X9ObjectIdentifiers.id_ecPublicKey, params)); //算法标识 v.add(privKey); DERSequence ds = new DERSequence(v); return ds.getEncoded(ASN1Encoding.DER); }
Example #2
Source File: BCECUtil.java From jiguang-java-client-common with MIT License | 5 votes |
/** * 将SEC1标准的私钥字节流恢复为PKCS8标准的字节流 * * @param sec1Key * @return * @throws IOException */ public static byte[] convertECPrivateKeySEC1ToPKCS8(byte[] sec1Key) throws IOException { /** * 参考org.bouncycastle.asn1.pkcs.PrivateKeyInfo和 * org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey,逆向拼装 */ X962Parameters params = getDomainParametersFromName(SM2Util.JDK_EC_SPEC, false); ASN1OctetString privKey = new DEROctetString(sec1Key); ASN1EncodableVector v = new ASN1EncodableVector(); v.add(new ASN1Integer(0)); //版本号 v.add(new AlgorithmIdentifier(X9ObjectIdentifiers.id_ecPublicKey, params)); //算法标识 v.add(privKey); DERSequence ds = new DERSequence(v); return ds.getEncoded(ASN1Encoding.DER); }