rsa

RSA与AES实现数据加密传输

泄露秘密 提交于 2020-01-12 13:00:29
RSA、AES简介 RSA:非对称加密,需要提前生成两个密钥(一对的),通过其中一个密钥加密后的数据,只有另一个密钥能解密。通常这两个密钥中有一个会暴漏出来,即对外公开的,这个密钥称为“公钥”,反之另一个是隐藏起来的,不公开的密钥称为“私钥”。 EAS:对称机密,数据的加密和解密都只使用同一个密钥。 关于加密传输   是为了保证数据 传输过程 中,数据即使被“中间人”截获,“中间人”也无法解析其中的数据,使“中间人”无法得知我们实际要传输的数据,以达到保护数据的目的。如果客户端本身存在安全问题,则无法保证数据的安全,如浏览器端JS变量存储了即将传输的用户密码,这个变量被其他非信任脚本或其他方式获取到了,会导致数据泄露,这种问题并不是加密传输所能处理的。加密传输能保障数据,有一个前提,那就是 对于本地动态生成的变量,就认为是安全的,是认为第三方无法获取的 。 RSA和AES配合实现加密传输 客户端往服务端传输加密数据 客户端每次请求前,都随机生成不同的AES密钥,保存到变量aesKey中 使用aesKey对要传输的信息进加密,得到加密内容A 通过预置在客户端的RSA公钥rsaPublicKey对aesKey加密,得到加密内容B 将内容A和内容B传输到服务端 服务端接收到内容A和内容B 使用预置在服务器端的RSA私钥rsaPrivateKey对内容B进行解密

Only RSAPrivate (Crt) KeySpec and PKCS8EncodedKeySpec supported for RSA private keys

橙三吉。 提交于 2020-01-12 08:38:53
问题 I following the steps from the link : How to read .pem file to get private and public key. I executed the following three commands: 1. $openssl genrsa -out mykey.pem 2048 2. $openssl pkcs8 -topk8 -inform PEM -outform PEM -in mykey.pem -out private_key.pem -nocrypt 3. $ openssl rsa -in mykey.pem -pubout -outform DER -out public_key.der This created three files, but when I was trying to read those through Java code I started facing below error: PUBLIC KEY EXPO : 65537 Only RSAPrivate(Crt

How to create public and private key with openssl?

柔情痞子 提交于 2020-01-12 07:08:19
问题 My question is how to create a public key and private key with OpenSSL in windows and how to put the created public key in .crt file and the private one in .pcks8 file in order to use this two keys to sign a SAML assertion in Java Thanks in advance 回答1: You can generate a public-private keypair with the genrsa context (the last number is the keylength in bits): openssl genrsa -out keypair.pem 2048 To extract the public part, use the rsa context: openssl rsa -in keypair.pem -pubout -out

RSA implementation using java

别来无恙 提交于 2020-01-12 03:52:28
问题 I am implementing RSA in java I have encountered a code which is given below it is showing plaintext in numeric form after decrypting the plaintext, but I want it in simple english which I entered. I don't want to use the java api. TestRsa.Java import java.io.IOException; import java.math.BigInteger; import java.util.Random; public class TestRsa { private BigInteger p, q; private BigInteger n; private BigInteger PhiN; private BigInteger e, d; public TestRsa() { initialize(); } public void

PEM to PublicKey in Android

假装没事ソ 提交于 2020-01-12 03:38:08
问题 I've seen a number of similar questions, but nothing has quite worked for me. I am simply trying to convert an RSA public key that's in PEM format that I've retrieved from a server into a PublicKey in Android. Can anyone point me in the right direction? EDIT: I've successfully used the following code to convert the PEM into a PublicKey, but upon encoding a message, I get unexpected output... public PublicKey getFromString(String keystr) throws Exception { // Remove the first and last lines

Small RSA or DSA lib without dependencies

断了今生、忘了曾经 提交于 2020-01-12 03:11:07
问题 Is there a small library for RSA or DSA without any dependencies like GMP or OpenSSL? (Written in C or Asm) 回答1: Take a look at axTLS it's a BSD licensed TLSv1 SSL in C for embedded systems. It's built for POSIX sockets, but is easily ported. The one thing it's missing is RSA key generation, but it can read X.509 certificates. It's about 32KB of code space with a small RAM footprint. 回答2: You may find LibTomCrypt useful. It's written in C, supports RSA and DSA (along with a host of other

How does RSA work while encrypting a sentence?

寵の児 提交于 2020-01-11 10:00:33
问题 I'm learning about RSA encryption and I have understood how to encrypt a single letter. I have problems understanding how does RSA work while encrypting a sentence. For eg: Single letter encryption: A Encryption= A^e (mod n) But in a sentence. For eg: Sentence encryption: Hello World Does each word get encrypted or does the sentences as a whole get encrypted? 回答1: Neither. In practice RSA is almost always coupled with a symmetric cipher such as AES to encrypt larger ciphertext. RSA in itself

How to prevent a man-in-the-middle attack in case of a compromised server?

混江龙づ霸主 提交于 2020-01-11 09:45:09
问题 Imagine that a server is serving public keys of the users to their partners to make encrypted communication possible. However, the server does NOT have access to the private keys.. Anyway - imagine the server is hacked and it sends not the requested public keys: Alice requests Bob's public key Server sends Eve's public key Bob requests Alice's public key Server sends Eve's public key Alice sends a message to Bob Server unpacks message, reads it and repacks it -> sends to Bob... Bob sends a

openssl RSA基本加密解密

允我心安 提交于 2020-01-11 08:56:21
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <openssl/bn.h> #include <openssl/rsa.h> #include <openssl/pem.h> int main(int argc, char *argv[]) { // 产生RSA密钥对 RSA *rsaKey = RSA_generate_key(1024, 65537, NULL, NULL); int keySize = RSA_size(rsaKey); char fData[]="aaabbbccdskjkfd"; char tData[128]; int flen = strlen(fData); //flen = 15 int ret = RSA_public_encrypt(flen, (unsigned char *)fData, (unsigned char *)tData, rsaKey, RSA_PKCS1_PADDING); //ret = 128 ret = RSA_private_decrypt(128, (unsigned char *)tData, (unsigned char *)fData, rsaKey, RSA_PKCS1_PADDING); //ret = 15 RSA

【网络】openssl及其使用

安稳与你 提交于 2020-01-11 06:42:36
介绍 OpenSSL是面向TLS和SSL协议的全能工具,同时也是一个通用的加解密工具。 此博客参考: openssl常用命令 https://www.sslshopper.com/article-most-common-openssl-commands.html 常用选项 -noout 不打印base64编码的key,在某些情况下,会省略输出相关信息 -modulus 显示用于计算公钥和私钥的模(见RSA) -new 创建 -nodes 不加密 -config file 指定额外的配置文件 -x509 在req命令中,用于创建自签名的证书而不是证书签名请求(CSR) -in file 从file读取内容 -inform FORM 指定输入的文件格式 -out file 将生成内容写到文件 -outform FORM 指定输出的文件格式 常用命令 生成RSA密钥 openssl genrsa -out private.key 2048 生成一个证书签名请求(CSR) openssl req -out CSR.csr -new -newkey rsa:2048 -nodes -keyout privateKey.key 检查RSA私钥 openssl rsa -in privateKey.key -check 输出证书细节 openssl x509 -in certificate