rsa

Java - Public-private key encryption - how to calculate private key in RSA

烈酒焚心 提交于 2020-04-13 18:14:13
问题 I worked on a code for an RSA algorithm and it returns the incorrect number, which happens to be huge. I am sure I coded everything right except for one line I was not sure about. I did not know how to solve for the private key in the RSA, and just winged it (I saw someone code d = e.modInverse(m); where d is the private key, e is the public key, and m is (p-1)*(q-1). I dont understand how the modInverse method works though. long story short, how do you actually solve for the 'd' without

Crypto++应用:非对称加密RSA

∥☆過路亽.° 提交于 2020-04-12 17:59:43
1,非对称加密RSA: (1)乙方生成两把密钥(公钥和私钥)。公钥是公开的,任何人都可以获得,私钥则是保密的。 (2)甲方获取乙方的公钥,然后用它对信息加密。 (3)乙方得到加密后的信息,用私钥解密。 2,使用CryptoPP实现RSA: CryptoPP是一套非常完整的加密解密开源解决方案,如何使用这里就不多说了,请自行Google。 #include "..\cryptopp562\randpool.h" #include "..\cryptopp562\osrng.h" #include "..\cryptopp562\rsa.h" //待加密的字符串 string message = "http://my.oschina.net/xlplbo/blog"; printf("message = %s, length = %d\n", message.c_str(), strlen(message.c_str())); /* //自动生成随机数据 byte seed[600] = ""; AutoSeededRandomPool rnd; rnd.GenerateBlock(seed, sizeof(seed)); printf("seed = %s\n", (char *)seed, strlen((char *)seed)); /

Automatically accept rsa fingerprint using pscp

做~自己de王妃 提交于 2020-04-11 18:10:08
问题 When you're using pscp to send files to a single machine is not a big deal because you will get the rsa fingerprint prompt once and never again after. But if you want to connect to 200 machines, you definitely don't want to type "yes" 200 times.... I'm using pscp on a Windows machine and I really don't care about the fingerprint, I only want to accept it. I'm using Amazon EC2 and the finger print change every time i restart the machines.... If there is a way to avoid it using pscp or a

Validating the token recieved from azure ad b2c using the Values from “jwks_uri” endpoint

倾然丶 夕夏残阳落幕 提交于 2020-04-10 15:05:13
问题 I am getting the azure ad access token from an Utility Service and I want to validate it using some standard token validation parameters which includes issuer, audience and issuer signing key.Now I have the issuer and audience but I don't have the issuer signing key. However I have extracted the key information using the jwks_uri end point of azure ad b2c which gives me a json output as { "keys": [ { "kid": "X5eXk4xyojNFum1kl2Ytv8dlNP4......", "nbf": 1493763266, "use": "sig", "kty": "RSA", "e

Any way to create a JWT token with key size 512? and changing default minimum size requirement of AsymmetricSignatureProvider

为君一笑 提交于 2020-04-07 08:27:28
问题 I am currently getting following error: IDX10630: The 'Microsoft.IdentityModel.Tokens.RsaSecurityKey, KeyId: '...', InternalId: '5a946596-9fe6-4c91-8c52-9b140849c7a4'.' for signing cannot be smaller than '2048' bits. KeySize: '512' I use the following method: public string GetIdTokenString(Dictionary<string, string> inputClaims, string privateKey) { string result = null; try { var tokenHandler = new JwtSecurityTokenHandler(); privateKey = privateKey.Replace("-----BEGIN ENCRYPTED PRIVATE KEY--

Any way to create a JWT token with key size 512? and changing default minimum size requirement of AsymmetricSignatureProvider

流过昼夜 提交于 2020-04-07 08:26:43
问题 I am currently getting following error: IDX10630: The 'Microsoft.IdentityModel.Tokens.RsaSecurityKey, KeyId: '...', InternalId: '5a946596-9fe6-4c91-8c52-9b140849c7a4'.' for signing cannot be smaller than '2048' bits. KeySize: '512' I use the following method: public string GetIdTokenString(Dictionary<string, string> inputClaims, string privateKey) { string result = null; try { var tokenHandler = new JwtSecurityTokenHandler(); privateKey = privateKey.Replace("-----BEGIN ENCRYPTED PRIVATE KEY--

[转帖]RSA 的原理与实现

我的梦境 提交于 2020-04-07 07:21:13
HOME RSA 的原理与实现 https://cjting.me/2020/03/13/rsa/ 1976 年以前,所有的加密都是如下方式: A 使用某种规则对信息进行处理 B 使用同样的规则对处理过的信息进行复原 这个方式很好理解,不论是非常简单的 ROT13 还是目前广泛使用的 AES,都是这种对称加密方式。 但是这种方式有一个巨大的缺点,那就是 A 需要将对信息进行处理的规则(也就是秘钥)告诉给 B。怎样安全地传输秘钥就成了一个非常棘手的问题。 那么存不存在一种方式,加密和解密使用不同的秘钥,彻底规避掉传输秘钥的问题? 答案是存在的,感谢数学家和计算机科学家,RSA 就是这样一种非对称加密方式,也就是: 使用算法可以生成两把钥匙 A 和 B 使用 A 加密的信息,使用 B 可以解开 使用 B 加密的信息,使用 A 可以解开 日常使用中,我们把一把作为公钥,公开发布。一把作为私钥,自己保留。这样,任何人都可以使用我们的公钥加密信息发给我们,我们则可以使用自己的私钥解开。 只要把私钥保存好,这个通信系统就非常安全。 数学原理 现在我们来看看这样一个神奇的系统背后的数学原理。数学作为人类智慧皇冠上最灿烂的明珠,永远是那么的冷静迷人。这里我只陈述内容,具体的证明如果感兴趣可以 Google。 首先我们梳理几个概念。 互质 如果两个正整数,除了 1 以外没有其他的公因数,则他们互质

由SecureCRT引发的思考和学习

好久不见. 提交于 2020-04-07 05:52:13
前言 由于业务需要,最近在云上新购买了一批centos7.0的服务器,用脚本批量添加了用户(脚本请见我之前的博客/秘钥认证用户自动控制: http://my.oschina.net/pwd/blog/388254 ),加完秘钥之后发现,但是secureCRT 抛出了一下异常。 解决过程 : 1.初步怀疑秘钥有问题,通过命令行去探测是否可以连接,-> ssh -i 秘钥文件 用户名@主机 ,发现能正常连接,确认秘钥是OK的。 2.可能出在secureCRT配置问题,具体操作不详解了,主要是涉及客户端一些可视化的设置,捣鼓完以后没好。 3.根据以上报错联想,可能是这个secureCrt 不支持以上的加密算法,上面已经明确的提示了,于是验证了xshell和putty,以及高版本的SecureCRT是可以连接. 常见终端客户端的介绍请戳链接: http://www.cnblogs.com/276815076/p/4409591.html 由于低版本 SecreCRT 不支持 AES-128-CBC 这个 Cipher,而 Linux 下用 ssh-keygen 生成的公钥默认采用这个 Cipher 的,于是对应的私钥可能会加载不了,所以登陆不上。 思考和学习 参考: http://blog.csdn.net/macrossdzh/article/details/5691924 一

Java加密工具类

送分小仙女□ 提交于 2020-04-06 23:52:15
加密工具类: package group.hound.starter.core.util; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; import java.security.*; import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPublicKey; import java.security.spec.InvalidKeySpecException; import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; import java.util.Base64; import javax.crypto.*; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.digest.DigestUtils; import org

常见数字证书类型

回眸只為那壹抹淺笑 提交于 2020-04-03 22:08:53
1 数字证书 1.1 概述   数字证书就是互联网通讯中标志通讯各方身份信息的一串数字,提供了一种在Internet上验证通信实体身份的方式,数字证书不是 数字身份证 ,而是身份认证机构盖在数字身份证上的一个章或印(或者说加在数字身份证上的一个签名)。它是由权威机构——CA机构,又称为证书授权(Certificate Authority)中心发行的,人们可以在网上用它来识别对方的身份。 2 证书格式 2.1 证书格式分类 分为2大类:密钥库(含私钥,也可能有公钥)和公钥证书(仅含公钥) 2.1.1 密钥库文件格式【Keystore】 格式 : JKS 扩展名 : .jks/.ks 描述 : 【Java Keystore】密钥库的Java实现版本,provider为SUN 特点 : 密钥库和私钥用不同的密码进行保护 格式 : JCEKS 扩展名 : .jce 描述 : 【JCE Keystore】密钥库的JCE实现版本,provider为SUN JCE 特点 : 相对于JKS安全级别更高,保护Keystore私钥时采用TripleDES 格式 : PKCS12 扩展名 : .p12/.pfx 描述 : 【PKCS #12】个人信息交换语法标准 特点 : 1、包含私钥、公钥及其证书 2、密钥库和私钥用相同密码进行保护 格式 : BKS 扩展名 : .bks 描述 :