예제 #1
0
  def AttachedSign(self, data, nonce):
    """
    Sign given data and nonce and return a blob containing both data and
    signature

    For message M, and nonce N, outputs Header|len(M)|M|Sig(Header|M|N).

    @param data: message to be signed
    @type data: string

    @param nonce: nonce to be included in the signature
    @type nonce: string

    @return: signature on the data encoded as a Base64 string
    @rtype: string
    """
    return util.Base64WSEncode(self.primary_key.Header()
                       + util.PackByteArray(data)
                       + self.__InternalSign(data, nonce))
예제 #2
0
  def AttachedSign(self, data, nonce, encoder=util.Base64WSEncode):
    """
    Sign given data and nonce and return a blob containing both data and
    signature

    For message M, and nonce N, outputs Header|len(M)|M|Sig(M|len(N)|N|VersionByte).

    @param data: message to be signed
    @type data: string

    @param nonce: nonce to be included in the signature
    @type nonce: string

    @return: signature on the data encoded as a Base64 string
    @rtype: string
    """
    signature = self.primary_key.Header() \
                + util.PackByteArray(data) \
                + self.__InternalSign(data, nonce)
    return encoder(signature) if encoder else signature
예제 #3
0
 def __InternalSign(self, data, nonce = None):
   signing_key = self.primary_key
   if signing_key is None:
     raise errors.NoPrimaryKeyError()
   return signing_key.Sign(data + util.PackByteArray(nonce) + VERSION_BYTE)
예제 #4
0
 def __InternalVerify(self, header,  signature, data, nonce = None):
   key = self._ParseHeader(header)
   return key.Verify(data + util.PackByteArray(nonce) + VERSION_BYTE, signature)