1 package com.quadcap.crypto; 2 3 40 41 import java.util.Random ; 42 43 import java.nio.ByteBuffer ; 44 45 50 public abstract class AbstractSymmetricKey implements SymmetricKey { 51 54 public abstract void init(String s) throws Exception ; 55 56 59 public abstract void init(Random r); 60 61 64 public abstract int getBlockSize(); 65 66 69 class EncryptionKey implements Key { 70 public void f(ByteBuffer m, ByteBuffer c) { 71 encrypt(m, c); 72 } 73 public int blockSize() { return getBlockSize(); } 74 } 75 protected EncryptionKey ekey = new EncryptionKey(); 76 77 80 public Key getEncryptionKey() { return ekey; } 81 82 85 public abstract void encrypt(ByteBuffer plain, ByteBuffer code); 86 87 90 class DecryptionKey implements Key { 91 AbstractSymmetricKey k = null; 92 public DecryptionKey(AbstractSymmetricKey k) { 93 this.k = k; 94 } 95 public int blockSize() { return getBlockSize(); } 96 public void f(ByteBuffer m, ByteBuffer c) { 97 if (k == null) { 98 decrypt(m, c); 99 } else { 100 k.decrypt(m, c); 101 } 102 } 103 } 104 protected DecryptionKey dkey = new DecryptionKey(this); 105 106 109 public Key getDecryptionKey() { return dkey; } 110 111 114 public abstract void decrypt(ByteBuffer code, ByteBuffer plain); 115 116 } 117
| Popular Tags
|