This repository was archived by the owner on Jan 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Asymmetric encryption
justinemclevy edited this page Jan 23, 2014
·
3 revisions
Maidsafe using RSA algorithm (which is an asymmetric encryption algorithm, using public key to encrypt and private key to sign, using public key to check signature and private key to decrypt) to encrypt data. This requires various key related types and functions to be presented. The rsa.h enlisted all of them, including: private/public key, signature, plain/cypher text, encoded private/public key ; generate key pair, encrypt/decrypt, sign/check signature, encrypt/decrypt key, validate public key, match key.
Named Types (Key, Signature, Text)
typedef CryptoPP::RSA::PrivateKey PrivateKey;
typedef CryptoPP::RSA::PublicKey PublicKey;
struct Keys {
// The signature will be the same size as the key size in bytes
// http://stackoverflow.com/questions/5403808/private-key-length-bytes
// http://stackoverflow.com/questions/6658728/rsa-signature-size
enum { kKeyBitSize = 2048, kSignatureByteSize = kKeyBitSize / 8 };
Keys() : private_key(), public_key() {}
PrivateKey private_key;
PublicKey public_key;
};
typedef detail::BoundedString<2> EncodedPublicKey;
typedef detail::BoundedString<3> EncodedPrivateKey;
typedef NonEmptyString PlainText, CipherText;
typedef detail::BoundedString<Keys::kSignatureByteSize> Signature;
Key Related Helper Functions (generate, encode/decode, validate and match)
Keys GenerateKeyPair();
EncodedPrivateKey EncodeKey(const PrivateKey& private_key);
EncodedPublicKey EncodeKey(const PublicKey& public_key);
PrivateKey DecodeKey(const EncodedPrivateKey& private_key);
PublicKey DecodeKey(const EncodedPublicKey& public_key);
bool ValidateKey(const PublicKey& public_key);
bool MatchingKeys(const PrivateKey& private_key1, const PrivateKey& private_key2);
bool MatchingKeys(const PublicKey& public_key1, const PublicKey& public_key2);
Encryption Related (sign/check sign, encrypt/decrypt)
CipherText Encrypt(const PlainText& data, const PublicKey& public_key);
PlainText Decrypt(const CipherText& data, const PrivateKey& private_key);
Signature Sign(const PlainText& data, const PrivateKey& private_key);
Signature SignFile(const boost::filesystem::path& filename, const PrivateKey& private_key);
bool CheckSignature(const PlainText& data, const Signature& signature, const PublicKey& public_key);
bool CheckFileSignature(const boost::filesystem::path& filename, const Signature& signature, const PublicKey& public_key);
MaidSafe Common Library
MaidSafe Project
- MaidSafe
- MaidSafe-API
- MaidSafe-Common
- MaidSafe-Passport
- MaidSafe-RUDP
- MaidSafe-Routing
- MaidSafe-Encrypt
- MaidSafe-Drive
- MaidSafe-Network-Filesystem
- MaidSafe-Vault
- MaidSafe-Vault-Manager
MaidSafe Papers