Always store keys as bytes since strings in some languages are known to be terminated by null value bytes. You can use a bytes32 attribute to store the key and a getter method to retrieve it from the deployed (instantiated) contract:
contract PubKey {
bytes32 pubKey;
function PubKey(bytes32 initKey) {
pubKey = initKey;
}
function getPubKey() constant returns (bytes32) {
return pubKey;
}
}
Edit:
The public key is 64 bytes long excluding its prefix:
contract PubKey {
uint8[] pubKeyBytes;
function PubKey(uint8[] initKey) {
for(uint i = 0; i < initKey.length; i++) {
pubKeyBytes.push(initKey[i]);
}
}
function getPubKeyByte(uint i) constant returns (uint) {
return pubKeyBytes[i];
}
This is expensive since each retrieval of the public key must be called 64 times. using two 32 byte chunks is cheaper (but uglier):
contract PubKey {
bytes32 pubKeyHalf1, pubKeyHalf2;
function PubKey(bytes32 initKeyHalf1, bytes32 initKeyHalf2) {
pubKeyHalf1 = initKeyHalf1;
pubKeyHalf2 = initKeyHalf2;
}
function getPubKeyHalf1() constant returns (bytes32) {
return pubKeyHalf1;
}
function getPubKeyHalf2() constant returns (bytes32) {
return pubKeyHalf2;
}
}