Sha256: afd40c73babaef0cacb4c67f098ce6b22a512607245a216add4615fcf13a269c

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

require 'spec_helper'

describe "RSA key generation" do
  it "should generate a key" do
    keypair = Gibberish::RSA.generate_keypair
    keypair.should be_instance_of(Gibberish::RSA::KeyPair)
  end

  it "should generate a key with custom bits" do
    keypair = Gibberish::RSA.generate_keypair(1024)
    keypair.should be_instance_of(Gibberish::RSA::KeyPair)
  end

  it "should answer to public and private key methods" do
    keypair = Gibberish::RSA.generate_keypair(1024)
    keypair.should be_instance_of(Gibberish::RSA::KeyPair)
    keypair.public_key.should_not be_nil
    keypair.private_key.should_not be_nil
  end

end

describe "RSA" do
  before do
    k = Gibberish::RSA.generate_keypair(1024)
    @cipher = Gibberish::RSA.new(k.public_key, k.private_key)
    @pub_cipher = Gibberish::RSA.new(k.public_key, k.private_key)
  end

  it "should encrypt/decrypt with a keypair" do
    encrypted = @cipher.encrypt("Some data")
    p encrypted
    decrypted = @cipher.decrypt(encrypted)
    encrypted.should match(/^[a-zA-Z0-9\+\\\n=]+$/) # Be base64
    decrypted.should eql("Some data")
  end

  it "should work without private key" do
    enc = @pub_cipher.encrypt("Some data")
    enc.should_not be_nil
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gibberish-0.0.2 spec/rsa_spec.rb