All Projects → MisterDaneel → PemToXml

MisterDaneel / PemToXml

Licence: GPL-2.0 license
Python script which converts RSA PEM key (PKCS#1) to XML compatible for .Net

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to PemToXml

Ctf Crypto
Contains tools for solving RSA and other crypto problems in CTFs.
Stars: ✭ 221 (+689.29%)
Mutual labels:  rsa
enigma
A fast, native, cryptographic engine for the web
Stars: ✭ 101 (+260.71%)
Mutual labels:  rsa
oseid
Microchip AVR based smartcard/token with ECC and RSA cryptography
Stars: ✭ 17 (-39.29%)
Mutual labels:  rsa
Network
C# Network Library
Stars: ✭ 237 (+746.43%)
Mutual labels:  rsa
cosign
Cooperative RSA signing
Stars: ✭ 25 (-10.71%)
Mutual labels:  rsa
encryption
A simple wrapper for the OpenSSL Cipher library for Ruby and Rails applications. Distributed as a Gem through Rubygems.
Stars: ✭ 28 (+0%)
Mutual labels:  rsa
Auth Jwt
A demo to learn JWT by reverse engineering
Stars: ✭ 208 (+642.86%)
Mutual labels:  rsa
rsa aes md5
RSA(SHA1withRSA/pem私钥0/crt证书公钥) + AES(256/AES/CBC/PKCS5Padding)
Stars: ✭ 11 (-60.71%)
Mutual labels:  rsa
pandorabox
基于非对称加密(RSA)的私密信息传递工具,数据由本地客户端进行加密、解密操作。
Stars: ✭ 18 (-35.71%)
Mutual labels:  rsa
rsa-encrypt-body-spring-boot
Spring Boot 接口请求参数自动加解密
Stars: ✭ 108 (+285.71%)
Mutual labels:  rsa
Illustrated Tls
The Illustrated TLS Connection: Every byte explained
Stars: ✭ 2,751 (+9725%)
Mutual labels:  rsa
accumulator
Cryptographic accumulators in Rust.
Stars: ✭ 115 (+310.71%)
Mutual labels:  rsa
optiga-trust-m
OPTIGA™ Trust M Software Framework
Stars: ✭ 86 (+207.14%)
Mutual labels:  rsa
Jsrsasign
The 'jsrsasign' (RSA-Sign JavaScript Library) is an opensource free cryptography library supporting RSA/RSAPSS/ECDSA/DSA signing/validation, ASN.1, PKCS#1/5/8 private/public key, X.509 certificate, CRL, OCSP, CMS SignedData, TimeStamp, CAdES JSON Web Signature/Token in pure JavaScript.
Stars: ✭ 2,760 (+9757.14%)
Mutual labels:  rsa
Computer-Security-algorithms
👨‍💻 Computer Security algorithms in C#
Stars: ✭ 48 (+71.43%)
Mutual labels:  rsa
Rsautil
.NET Core RSA algorithm using the help tool.It supports data encryption, decryption, signature and verification signature.It supports three key formats, namely: xml, pkcs1, pkcs8.It also supports key conversion for these three formats.Last also support pem formatting.
Stars: ✭ 218 (+678.57%)
Mutual labels:  rsa
pkcs11js
A Node.js implementation of the PKCS#11 2.3 interface. (Keywords: Javascript, PKCS#11, Crypto, Smart Card, HSM)
Stars: ✭ 95 (+239.29%)
Mutual labels:  pkcs
signature
HMAC and RSA signature for Laravel and Lumen
Stars: ✭ 26 (-7.14%)
Mutual labels:  rsa
keystore-idb
In-browser key management with IndexedDB and the Web Crypto API
Stars: ✭ 37 (+32.14%)
Mutual labels:  rsa
cryptotools
No description or website provided.
Stars: ✭ 182 (+550%)
Mutual labels:  rsa

PemToXml

Converting RSA PEM key (PKCS#1) to XML compatible for .Net

Requirements:

  1. Tested with python version 2.7
  2. Uses pycrypto

For windows you may find binaries here: http://www.voidspace.org.uk/python/modules.shtml#pycrypto

Tested scenarious:

  1. PHP encrypt/decrypt using PEM keys, C# decrypt using coverted PEM to XML keys
  2. C# encrypt/decrypt using using XML keys, PHP decrypt using coverted XML to PEM keys

Usage:

Convert a public key from XML to PEM: python PemToXml.py -ptox -pub "path/to/public.pem"

Convert a public key from PEM to XML: python PemToXml.py -xtop -pub "path/to/public.xml"

Convert a public key from XML to PEM: python PemToXml.py -ptox -priv "path/to/private.pem"

Convert a public key from PEM to XML: python PemToXml.py -xtop -priv "path/to/private.xml"

.Net example

using System;
using System.Text;
using System.Security.Cryptography;
private static readonly string privateKeyXml = "...your XML here...";
private static readonly string publicKeyXml = "...your XML here...";

// see https://msdn.microsoft.com/en-us/library/system.security.cryptography.rsacryptoserviceprovider.aspx
// let exception be thrown if error
public static string Encrypt(string data)
{
    if (string.IsNullOrEmpty(data))
    {
  		return null;
    }
    byte[] dataToEncrypt = Encoding.UTF8.GetBytes(data);
    byte[] encryptedData;
    using (var rsa = new RSACryptoServiceProvider())
    {
        rsa.FromXmlString(publicKeyXml);
        encryptedData = rsa.Encrypt(dataToEncrypt, false);
    }
    return Convert.ToBase64String(encryptedData); 
}

// let exception be thrown if error
public static string Decrypt(string data)
{
    if (string.IsNullOrEmpty(data))
    {
        return null;
    }
    byte[] dataToDencrypt = Convert.FromBase64String(data);
    byte[] decryptedData;
    using (var rsa = new RSACryptoServiceProvider())
    {
        rsa.FromXmlString(privateKeyXml);
        decryptedData = rsa.Decrypt(dataToDencrypt, false);
    }
    return Encoding.UTF8.GetString(decryptedData);
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].