public-key-encryption

Encryption using PKCS#7

风流意气都作罢 提交于 2019-12-01 14:27:55
I am using Bouncy Castle provided library to encrypt,decrypt,sign and verify sign. I am doing this as 1. Encrypt data 2. Sign data 3. Write signed byte to a file 4. Read signed byte from file 5. Verify signature 6. Decrypt data I have taken reference from Beginning Cryptography with Java My problem is in step 5 when i am verifying data i am getting org.bouncycastle.cms.CMSException: message-digest attribute value does not match calculated value My code is below import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java

Encryption using PKCS#7

妖精的绣舞 提交于 2019-12-01 12:45:19
问题 I am using Bouncy Castle provided library to encrypt,decrypt,sign and verify sign. I am doing this as 1. Encrypt data 2. Sign data 3. Write signed byte to a file 4. Read signed byte from file 5. Verify signature 6. Decrypt data I have taken reference from Beginning Cryptography with Java My problem is in step 5 when i am verifying data i am getting org.bouncycastle.cms.CMSException: message-digest attribute value does not match calculated value My code is below import java.io

Xml Signature for XmlElement fails to verify

烈酒焚心 提交于 2019-12-01 11:11:48
I apologize in advance for the rather lengthy block of code, but it's the smallest compilable example I could produce. I already omitted all error checking from the original code. I'm using Visual Studio 2012 and .NET 4.5, although this is nothing new to 4.5, it should work with any version. I am trying to sign an XML documents' elements to protect them from tampering. I don't want to protect the whole document, but only certain elements. Maybe even different elements with different keys. However, when I sign three example elements and try to verify them, the first one always verifies, the

Reading a PKCS#1 or SPKI public key in Java without libraries

孤街醉人 提交于 2019-12-01 11:06:53
I need to use a public key to verify some data in Java, but I can't seem to format the key in such a way that Java can use without third-party plugins. I'm generating the key with Node.js's crypto library, which gives me the option of PKCS#1 or SPKI , and either .pem or .der file format. I've heard that Java doesn't support PKCS#1 out-of-the box, and pretty much every other answer on StackOverflow recommends using BouncyCastle or similar, but in my case, I am writing an SDK, and simply cannot afford to use a library just to read this public key. So I'm currently reading the key in .der format

Java BC SicBlockCipher direct output equivalent in c#

倾然丶 夕夏残阳落幕 提交于 2019-12-01 11:04:15
问题 I am implementing something in C#, for which I have a separate spec and fairly clear understanding of what I need to do, but at the same time as a reference I have a Java implementation and would like to follow the Java implementation in this case as close as I can. The code involves an encrypted stream and the Java source is here The relevant lines are here: private final StreamCipher enc; ... BlockCipher cipher; enc = new SICBlockCipher(cipher = new AESEngine()); enc.init(true, new

How to encrypt a string using public key cryptography

风流意气都作罢 提交于 2019-12-01 10:49:06
I am trying to implement my own RSA encryption engine. Given these RSA algorithm values: p = 61. // A prime number. q = 53. // Also a prime number. n = 3233. // p * q. totient = 3120. // (p - 1) * (q - 1) e = 991. // Co-prime to the totient (co-prime to 3120). d = 1231. // d * e = 1219921, which is equal to the relation where 1 + k * totient = 1219921 when k = 391. I am trying to write a method to encrypt each byte in a string and return back an encrypted string: public string Encrypt(string m, Encoding encoding) { byte[] bytes = encoding.GetBytes(m); for (int i = 0; i < bytes.Length; i++) {

How to replicate hash_hmac('sha256', $key, $secret_key) function in Swift 4?

假装没事ソ 提交于 2019-12-01 09:33:57
I've tried generating the hash_hmac('sha256', $key, $secret_key) php function equivalent in Swift 4 without success, after using libraries like CommonCrypto, CryptoSwift. I need these function for API authentication, using Alamofire library, which is a great library. Since i use Swift 4 the compatibility with other Swift libraries is not so good. Even with CryptoSwift which has the latest version(0.7.1) for Swift 4 i still get a lot of compatibility errors likes enter image description here Swift 3/4: HMAC with MD5, SHA1, SHA224, SHA256, SHA384, SHA512 (Swift 3) These functions will hash

Xml Signature for XmlElement fails to verify

。_饼干妹妹 提交于 2019-12-01 07:48:48
问题 I apologize in advance for the rather lengthy block of code, but it's the smallest compilable example I could produce. I already omitted all error checking from the original code. I'm using Visual Studio 2012 and .NET 4.5, although this is nothing new to 4.5, it should work with any version. I am trying to sign an XML documents' elements to protect them from tampering. I don't want to protect the whole document, but only certain elements. Maybe even different elements with different keys.

Public key encryption in Internet Explorer 11

早过忘川 提交于 2019-12-01 07:39:24
问题 I am trying to implement public key encryption using JavaScript for IE11 with the following code: <script> var data = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); var crypto = window.crypto || window.msCrypto; var cryptoSubtle = crypto.subtle; var genOp = cryptoSubtle.generateKey( { name: "RSA-OAEP", modulusLength: 2048, publicExponent: new Uint8Array([0x01, 0x00, 0x01]), hash: { name: "SHA-256" }, }, true, ["encrypt", "decrypt"] ); genOp.onerror = function (e) { console.error(e); }; genOp

Use previously generated private key in ECIES

你。 提交于 2019-12-01 06:26:23
I wan to encrypt /decrypt data using ECIES , I am using cryptopp for this. AutoSeededRandomPool prng; //get private key generated ECIES<ECP>::Decryptor d0(prng, ASN1::secp256r1()); PrintPrivateKey(d0.GetKey()); //get public key ECIES<ECP>::Encryptor e0(d0); PrintPublicKey(e0.GetKey()); //encrypt the message string em0; // encrypted message StringSource ss1 (message, true, new PK_EncryptorFilter(prng, e0, new StringSink(em0) ) ); //decrypt the message string dm0; // decrypted message StringSource ss2 (em0, true, new PK_DecryptorFilter(prng, d1, new StringSink(dm0) ) ); Everything else is fine