bouncycastle

Port RSA encryption Java code to C#

最后都变了- 提交于 2021-02-05 20:35:21
问题 I'm trying to port the following Java code to a C# equivalent: public static String encrypt(String value, String key) throws InvalidKeySpecException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException { byte[] bytes = value.getBytes(Charset.forName("UTF-8")); X509EncodedKeySpec x509 = new X509EncodedKeySpec(DatatypeConverter.parseBase64Binary(key)); KeyFactory factory = KeyFactory.getInstance("RSA"); PublicKey publicKey =

Instantiate java.security classes PrivateKey and X509Certificate from .key and .cer files

与世无争的帅哥 提交于 2021-01-29 09:33:17
问题 The original goal is: Generate a https url where one of parameters is PKCS7 detached signature (RSA, SHA-256, UTF-8, BASE64). What do I have: private key (.key file begin with "-----BEGIN RSA PRIVATE KEY-----", end like this "kIng0BFt5cjuur81oQqGJgvU+dC4vQio+hVc+eAQTGmNQJV56vAHcq4v -----END RSA PRIVATE KEY-----") self signed certificate (.cer file begin with "-----BEGIN CERTIFICATE-----", end like this "xwRtGsSkfOFL4ehKn/K7mgQEc1ZVPrxTC7C/g+7grbKufvqNmsYW4w== -----END CERTIFICATE-----") data

Using BouncyCastle, how do I generate a certificate for any kind of key algorithm?

天大地大妈咪最大 提交于 2021-01-29 07:03:15
问题 I want to store a KeyPair inside AndroidKeyStore , which requires creating a certificate. This answer worked fine for RSA keys, but the KeyPair in my case is supplied by an ssh library and can be several kinds of keys, including DSA , RSA , EC and Ed25519 keys. I came up with this code, which seems to work: private interface SignerBuilder { BcContentSignerBuilder make(AlgorithmIdentifier sigAlgId, AlgorithmIdentifier digAlgId); } // adapted from answer by Tolga Okur https://stackoverflow.com

Bouncy Castle FIPS mode for PKCS#12 KeyStore Format

╄→尐↘猪︶ㄣ 提交于 2021-01-28 19:05:54
问题 Does Bouncy Castle FIPS support "PKCS12" as KeyStore/trustStore? I read somewhere that in the approved mode it doesn't support PKCS#12 format but that it is supported in non approved mode (the generally used libraries). 回答1: Quoting from the BC-FJA user guide, section "7. Key Stores": The PKCS12 key store is not available in approved-mode of operation due to the algorithms required for PBE key generation in the PKCS#12 standard. It is available only to threads that are not running in approved

Bouncy Castle convert ASN.1 to r and s byte arrays

徘徊边缘 提交于 2021-01-28 13:31:52
问题 I have the following code that generates a digital signature: byte[] GetSignature(byte[] message, byte[] privateKey) { var ecParams = NistNamedCurves.GetByName("P-256"); var domainParameters = new ECDomainParameters(ecParams.Curve, ecParams.G, ecParams.N, ecParams.H, ecParams.GetSeed()); var d = new BigInteger(1, privateKey); var privateKeyParameters = new ECPrivateKeyParameters(d, domainParameters); var signer = SignerUtilities.GetSigner("SHA-256withECDSA"); signer.Init(true,

Bouncy Castle convert ASN.1 to r and s byte arrays

岁酱吖の 提交于 2021-01-28 13:31:30
问题 I have the following code that generates a digital signature: byte[] GetSignature(byte[] message, byte[] privateKey) { var ecParams = NistNamedCurves.GetByName("P-256"); var domainParameters = new ECDomainParameters(ecParams.Curve, ecParams.G, ecParams.N, ecParams.H, ecParams.GetSeed()); var d = new BigInteger(1, privateKey); var privateKeyParameters = new ECPrivateKeyParameters(d, domainParameters); var signer = SignerUtilities.GetSigner("SHA-256withECDSA"); signer.Init(true,

BouncyCastle CMSSignedData from external signature and public key certificate

五迷三道 提交于 2021-01-28 11:42:17
问题 I have an X509Certificate, and a byte array that represents a raw signature created by a remote server (which has my private key). I'm trying to add this signature with PDFBox 2.0.18. For that, I need CMSSignedData object. How do I generate CmsSignedData without private key (only signature, public key, certificate)? 来源: https://stackoverflow.com/questions/60242213/bouncycastle-cmssigneddata-from-external-signature-and-public-key-certificate

How to avoid bcprov-jdk16-1.45.jar while running the application through POM entry

只愿长相守 提交于 2021-01-28 10:58:36
问题 I have a Java 8 application running in Weblogic 12.1.3. The application uses iText 5.5.9 and minimum version of BC required is 1.49 . The application is deploying as a WAR file in Weblogic . I could see the war file is having the proper version of BC . But during run time its taking from WebLogic maven plugin path and using BC 1.45. Is there any way we can avoid this by editing POM entry or by editing WebLogic.xml . If i remove BC 1.45 jar from my local server its running successfully. But i

RSA public key generated in Java is not valid in php

独自空忆成欢 提交于 2021-01-27 23:21:04
问题 I'm creating a RSA key pair in Java and want to use it in PHP. Java code is as follows: public static boolean keyGen() throws NoSuchAlgorithmException, IOException, OperatorCreationException, InvalidKeySpecException { KeyPairGenerator kpGen = KeyPairGenerator.getInstance("RSA"); kpGen.initialize(2048, new SecureRandom()); KeyPair keyPair = kpGen.generateKeyPair(); PublicKey pub = keyPair.getPublic(); byte[] pubBytes = pub.getEncoded(); SubjectPublicKeyInfo spkInfo = SubjectPublicKeyInfo

Can somebody help me to implement extension Subject Alternative Names using BouncyCastle?

大兔子大兔子 提交于 2021-01-27 22:59:01
问题 I have some string, that is separated with comma. I have to add all extension that match any of GeneralName for Subject Alternative Names extension. Can somebody finish for loop for me? @Override public boolean saveKeypair(String arg0) { KeyPair keyPair = generateKeyPair(Integer.parseInt(access.getPublicKeyParameter())); PrivateKey privateKey = keyPair.getPrivate(); PublicKey publicKey = keyPair.getPublic(); X500Name name = new X500Name(access.getSubject()); BigInteger serial = new BigInteger