encryption

java - decrypt a file with base64

你。 提交于 2021-02-07 11:10:26
问题 In my project a textfile is chosen and become encrypted. The encrypted text is saved seperatly as well as the key. Now I try to create a program which is decrypting the file when the right keyfile is available. I think the decrypting program needs to look pretty like the encrypting program just in DECRYPT_MODE . When I read in the key I don't know how to do the next step at it to decrypt the textfile. Maybe anyone can help me how I use the key from .txt file and use it to decrypt the encoded

How to sign and encrypt a message using S/MIME in PowerShell

点点圈 提交于 2021-02-07 10:12:35
问题 I am attempting to create a PowerShell script that will: Build a message Sign the message using my private S/MIME certificate Encrypt the message using the S/MIME public cert of the recipient Send the email that has been signed and encrypted I have included the full script below but changed email addresses, cert names, etc. The private cert has been imported onto the machine using Internet Explorer. It is then referenced within the directory C:\Users\xxx\AppData\Roaming\Microsoft

How to sign and encrypt a message using S/MIME in PowerShell

依然范特西╮ 提交于 2021-02-07 10:06:03
问题 I am attempting to create a PowerShell script that will: Build a message Sign the message using my private S/MIME certificate Encrypt the message using the S/MIME public cert of the recipient Send the email that has been signed and encrypted I have included the full script below but changed email addresses, cert names, etc. The private cert has been imported onto the machine using Internet Explorer. It is then referenced within the directory C:\Users\xxx\AppData\Roaming\Microsoft

C# BouncyCastle RSA Encryption and Decryption

大兔子大兔子 提交于 2021-02-07 08:16:35
问题 There are many topics on RSA Encryption and Decryption using BouncyCastle, however I'm encountering some unexpected behaviour. I'm attempting to encrypt a 64 byte data blocking using a private key of size 64 bytes I compute the RSA Encryption as followings: public byte[] Encrypt(byte[] data, AsymmetricKeyParameter key) { var engine = new RsaEngine(); engine.Init(true, key); var blockSize = engine.GetInputBlockSize(); return engine.ProcessBlock(data, 0, blockSize ); } I compute the decryption

C# BouncyCastle RSA Encryption and Decryption

家住魔仙堡 提交于 2021-02-07 08:15:21
问题 There are many topics on RSA Encryption and Decryption using BouncyCastle, however I'm encountering some unexpected behaviour. I'm attempting to encrypt a 64 byte data blocking using a private key of size 64 bytes I compute the RSA Encryption as followings: public byte[] Encrypt(byte[] data, AsymmetricKeyParameter key) { var engine = new RsaEngine(); engine.Init(true, key); var blockSize = engine.GetInputBlockSize(); return engine.ProcessBlock(data, 0, blockSize ); } I compute the decryption

How to generate persisted key for AES

最后都变了- 提交于 2021-02-07 08:13:24
问题 In the .NET Framework 4.6.2 Microsoft added support for persisted-key symmetric encryption using a CNG key storage provider and the AesCng algorithm. The documentation for instantiating the AesCng class using an existing key is pretty clear - just pass the key name into the constructor. But how do I generate a new persisted key to use for AES encryption? I can't find the instructions in the release notes or the documentation. Is this even possible from C#? 回答1: While not documented well, this

Chained GZipStream/DeflateStream and CryptoStream (AES) breaks when reading

我怕爱的太早我们不能终老 提交于 2021-02-07 06:53:40
问题 I want to compress and then encrypt my data, and for improved speed (by not having to write to byte arrays and back) decided to chain the streams used for compression and encryption together. It works perfectly when I write (compress and encrypt) the data, but when I try to read the data (decompress and decrypt), the Read operation breaks - simply calling Read once reads exactly 0 bytes, because the first Read always returns 0. Looping as in the below code almost works, except that at a

Java SecretKeyFactory generated key is same as input password

匆匆过客 提交于 2021-02-07 04:31:26
问题 I'm trying to generate a secret key using PBE but the secret key generated by the SecretKeyFactory is exactly the same as the input password. I've tried different algorithms, iteration counts etc. and it is still the same so I feel I'm missing a step here. public SecretKey generateKey(String password, String salt) { char[] passChars = password.toCharArray(); byte[] saltBytes = salt.getBytes(); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithHmacSHA256AndAES_128");

Java SecretKeyFactory generated key is same as input password

ぐ巨炮叔叔 提交于 2021-02-07 04:31:05
问题 I'm trying to generate a secret key using PBE but the secret key generated by the SecretKeyFactory is exactly the same as the input password. I've tried different algorithms, iteration counts etc. and it is still the same so I feel I'm missing a step here. public SecretKey generateKey(String password, String salt) { char[] passChars = password.toCharArray(); byte[] saltBytes = salt.getBytes(); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithHmacSHA256AndAES_128");

AES CBC Encryption With PKCS7Padding Has Different Results In Java And Objective-C

馋奶兔 提交于 2021-02-07 04:21:10
问题 I have created an application for Android in Java and used Cipher class to encrypt data with AES. Now I wanna take that algorithm into iOS with CommonCrypto class. The code works but has different results. This is the code in Java : public static String Decrypt(String text, String key) throws Exception { Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); byte[] keyBytes = new byte[16]; byte[] b = key.getBytes("UTF-8"); int len = b.length; if (len > keyBytes.length) len = keyBytes