cryptography

How to read an RSA key from file

a 夏天 提交于 2020-01-01 09:44:11
问题 I need to read in an RSA private key from a file to sign a JWT. I have found some examples on how to save a generated RSA key to disk but nothing showing how to build a key struct based on a pre-generated key from a file. The key is generated like this: openssl genrsa 2048 | openssl pkcs8 -topk8 -nocrypt Example key: -----BEGIN PRIVATE KEY----- MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQClHYNDPVSF‌​FmWF oKGTqd/n7Dt2+tGXh97KJjVLAqCBZZHlQJ534v2OzFjTgzuMNehD9Y6HnkYF‌​dkRb

iOS SecKeyRef (Public Key) send it to server [duplicate]

前提是你 提交于 2020-01-01 09:04:25
问题 This question already has answers here : Extracting a public key from key pair in key chain (2 answers) Closed 6 years ago . Now I have a problem with my public key, I used SecKeyGeneratePair to generate public and private. Now i have to send my public key to the server. I have used the below method to convert SecKeyRef to NSData, there always I am getting same public key. However I converted it into base64 format and send it to the server. But its not working at all and server(Java) start

ASPNET_REGIIS: Place AES key and IV into a KeyContainer

早过忘川 提交于 2020-01-01 08:21:02
问题 Is it possible to place an AES key and IV into a KeyContainer using ASPNET_REGIIS? If yes, how? Context: I have created AesProtectedConfigurationProvider to encrypt web.config data using AES as opposed to Triple DES (i.e., 3DES). I have also created a console application that uses the AesProtectedConfigurationProvider in order to generate both the AES key and initialization vector (IV). I can save the key to a text file and then reference the text file in the provider of the web.config. From

Simple cryptography: decryption algorithm needed in PHP

给你一囗甜甜゛ 提交于 2020-01-01 07:32:10
问题 I'm working the webpage that I have some text like this: AA,BB,CC,A1,B2,C3 And I want some code to replace the the word (like AA) to the string that saved in variable for example this is my php variable: <?php $var1 = "A"; //For AA $var2 = "B"; //For BB $var3 = "C"; //For CC $var4 = "1"; //For A1 $var5 = "2"; //For B2 $var6 = "3"; //For C3 ?> And the text AA,BB,CC,A1,B2,B3 will be like this: ABC123 How can I do this with php? In summery I need a decryption algorithm for a cypher text of AA,BB

ECDSA signing file with key from store C#.Net CNG

岁酱吖の 提交于 2020-01-01 07:30:31
问题 I'm trying to sign a file with ECDSA using the CNG API and a certificate from the Microsoft Certificate Store. I've read through a lot of documentation and and near done but I get hung up on importing the private key from the certificate. I've done this very same thing with RSA but it appears to be done very differently. Here's the code I have so far: static void signFile() { X509Certificate2 myCert = selectCert(StoreName.My, StoreLocation.CurrentUser, "Select a Certificate", "Please select a

Java - asymmetric encryption of traffic with pre-shared public keys and without trust store hassles

二次信任 提交于 2020-01-01 07:13:07
问题 I'm trying to communicate using RSA preshared keys and, ideally, without involving truststore shenanigans The setup is basically like this: There's an applet on client side and a servlet on server side (duh :) ) The applet has servlet's RSA public key (Spub) hardcoded. The servlet has it's own RSA private key (Spriv) hardcoded. They applet generates a random AES 256 key (session key), encrypts it with servlet's public key (which it has hardcoded), connects to the servlet over a TCP socket and

Speed difference between AES/CBC encryption and decryption?

本秂侑毒 提交于 2020-01-01 05:48:08
问题 I am wondering, theoretically, how much slower would AES/CBC decryption be compared to AES/CBC encryption with the following conditions: Encryption key of 32 bytes (256 bits); A blocksize of 16 bytes (128 bits). The reason that I ask is that I want to know if the decryption speed of an implementation that I have is not abnormally slow. I have done some tests on random memory blocks of different sizes. The results are as follows: 64B: 64KB: 10MB – 520MB: All data was stored on the internal

Produce MD5 or SHA1 hash code to long (64 bits)

情到浓时终转凉″ 提交于 2020-01-01 05:26:06
问题 I need to compute a hash code of a string and store it into a 'long' variable. MD5 and SHA1 produce hash codes which are longer than 64 bits (MD5 - 128 bits, SHA1 - 160 bit). Ideas any one? Cheers, Doron 回答1: You can truncate the hash and use just the first 64 bits. The hash will be somewhat less strong, but the first 64 bits are still extremely likely to be unique. For most uses of a hash this is both a common and perfectly acceptable practice. You can also store the complete hash in two 64

How to encrypt and save a binary stream after serialization and read it back?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-01 05:24:10
问题 I am having some problems in using CryptoStream when I want to encrypt a binary stream after binary serialization and save it to a file. I am getting the following exception System.ArgumentException : Stream was not readable. Can anybody please show me how to encrypt a binary stream and save it to a file and deserialize it back correctly? The code is as follows: class Program { public static void Main(string[] args) { var b = new B {Name = "BB"}; WriteFile<B>(@"C:\test.bin", b, true); var bb

Behaviour of SecureRandom

心已入冬 提交于 2020-01-01 05:10:13
问题 Even though after following many articles on SecureRandom , I encountered a doubt with the usage of SecureRandom Security API in Java. In the below example . public class SecureRandomNumber { public static void main(String[] args) throws NoSuchAlgorithmException { TreeSet<Integer> secure = new TreeSet<Integer>(); TreeSet<Integer> unSecure = new TreeSet<Integer>(); SecureRandom sr = new SecureRandom(); byte[] sbuf = sr.generateSeed(8); ByteBuffer bb = ByteBuffer.wrap(sbuf); long d = bb.getLong